Hi everyone,
I’m writing a plugin that adds a custom post type with some meta fields. Then, using the ‘the_post’ hook, if the current post is that custom post type and if those meta fields are there, I update the $post_content to contain the information from those meta fields in a specifically-formatted way.
I was developing this locally, and testing with the default Twenty Twenty theme and everything worked fine. When I tried to install my plugin on my live site, which uses X theme, the content is not getting updated as I would expect. I also deactivated every other plugin to make sure that a plugin wasn’t causing the problem. On my live site, I temporarily switched to another theme, and the plugin worked as expected. I switched back to X theme, and it’s not. I then installed and activated X theme locally and saw the same result. This was to make sure I hadn’t done anything within the X settings on my live site that would be causing this problem. With a pure vanilla install of X, this issue was still there.
I’m hoping someone can shed some light on what I need to do differently to make this work for x-theme. Here are the details:
Wordpress version: 5.4.2
X version: 7.2.3
Stack: Integrity
Here is the code I am using in my plugin:
function my_custom_post_type_the_post($post_object)
{
// The post object is passed to this hook by reference so there is no need to return a value.
if(
$post_object->post_type == 'my_custom_post_type' &&
( is_post_type_archive('my_custom_post_type') || is_singular('my_custom_post_type') ) &&
! is_admin()
) {
$video = get_post_meta($post_object->ID, 'my_custom_post_type_video_url', true);
$mp3 = get_post_meta($post_object->ID, 'my_custom_post_type_mp3_url', true);
$textfield = get_post_meta($post_object->ID, 'my_custom_post_type_textfield', true);
// Convert meta data to HTML-formatted media content
$media_content = $this->create_media_content($video, $mp3, $bible);
// Prepend $media_content to $post_content
$post_object->post_content = $media_content . $post_object->post_content;
}
}
add_action( 'the_post', 'my_custom_post_type_the_post' );
Again, this is working perfectly in the Twenty Twenty default WordPress theme, but not with my X setup for some reason. Any help would be appreciated.
EDIT: I just now tried this plugin with some other themes. It works in Twenty Twenty, but it does not display in Twenty Nineteen or Twenty Seventeen either. I can’t imagine what the problem is.