Created
February 19, 2024 16:29
-
-
Save taricco/5d6a486373c5267a5eca7f510bc7eb6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** Set default editor content for Video CPT using a specific Local Pattern | |
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/ | |
function add_or_replace_content_with_gb_template_for_video_posts($data, $postarr) { | |
// Only target the 'video' post type | |
if ($data['post_type'] == 'cpt_name') { | |
// Define your gblocks_templates Post ID | |
$gb_template_post_id = 123; // Replace 5501 with your actual gblocks_templates Post ID | |
// Get the content of the gblocks_templates post | |
$gb_template_post = get_post($gb_template_post_id); | |
if ($gb_template_post && !is_wp_error($gb_template_post)) { | |
// Use the content of the gblocks_templates post | |
$data['post_content'] = $gb_template_post->post_content; | |
} else { | |
// Optional: Handle error, log it or set default content | |
error_log('Failed to fetch gblocks_templates content. Using default content.'); | |
// $data['post_content'] = 'Your default content or leave as is'; | |
} | |
} | |
return $data; | |
} | |
add_filter('wp_insert_post_data', 'add_or_replace_content_with_gb_template_for_video_posts', 99, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment