Customizing preview for custom post type
-
Hello,
I created a custom post type (“comparator”), it has some acf fields, I use it as a shortcode, and I fetch some so extra data from an api and save them as meta when saving the post.
Everything works very well.This post type will never be displayed alone, only through a shortcode.
But I want to make the “review” works, so the editor can see his works before saving or updating.
I made this, but it has several flaws I think:Public function comparator_filter_content( $content ) { if ( ! is_singular( 'comparator' ) ) { return $content; } // Get the preview id $preview_post_list = get_posts( [ 'post_status' => 'any', 'post_parent' => intval( $_GET['preview_id'] ), 'post_type' => 'revision', 'sort_column' => 'ID', 'sort_order' => 'desc', 'posts_per_page' => 1 ] ); $preview_post = $preview_post_list[ array_key_last( $preview_post_list ) ]; $preview_post_id = $preview_post->ID; // Preview doesn't get the google sheet, so we do it ourselves : import_sheet( $preview_post_id ); // Get the data and launch the display of the comparator, as I do in the function comparator_shortcode ... }1. I’m not sure this function will be called only when previewing. Since I use my comparators only in shortcode it should be ok. But for instance, what about revisions? Or other things? Is there no better hooks that I could use to deal with in this “preview case”?
2. Using array_key_last is a big asumption. I have no idea if my preview will always be the last of this preview_post_list.
3. As said, I would like the revision to work, so it may interfere at some pointThat’s it, maybe I’m totally in the wrong direction, any help appreciated!
Thanks
The topic ‘Customizing preview for custom post type’ is closed to new replies.