Support » Plugins » Custom Post Types and Plugins

  • Resolved whipd09



    I can’t seem to find any discussion on this. (In regards to custom post types and WordPress 3)

    If you have existing plugins (pre WP3 plugins) that operate within the Add New Post screen (eg. a Related Posts box that let’s you choose related posts to the new post you’re creating). Is there an easy way to make them work for Custom Post Type situations as well? Or does it require the plugin author to make drastic changes to work with Custom Post Types in the WP3 era?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Or does it require the plugin author to make drastic changes to work with Custom Post Types in the WP3 era?

    Most likely. But you might want to provide a link to the related posts plugin you are talking about and I’ll tag this thread so the plugin author might see your request.

    Yeah, thanks It’s the Microkids Related Posts

    Should not be difficult at all provided the plugin author hasn’t encrypted their code.
    Is explained well here:

    Thanks qw3rt7! You’ve saved me a lot of time.

    Hi whipd09,

    I’m trying to find the time to do some updates on my plugin soon. Can you elaborate on what you would like to see in a new version regarding the new Custom Post Types feature?


    Thanks for the reply microkid.

    The plugin is amazing in itself, so basically I’d just like to be able to use it with custom post types. If you saw me in that other thread I managed to ‘hack’ it to appear in a custom post type but it still searches for regular posts instead of the new post types.

    So it would be great if:
    1. If I had a Custom Post Type of ‘Portfolio‘. When I create a new portfolio post, I can choose a couple of related portfolio posts to accompany it. The ability to have the plugin ignore regular posts would be great, because in this instance they would not apply to what I’m using the plugin for.

    2. Also, I can’t remember if it supports Post Thumbnails(‘Featured Images’) in the output of each related post? I managed to get a friend to hack the ability in but it would be great if it was built in or better documented.

    Justin Tadlock


    WordPress God

    I’m not going to go looking through other people’s plugins, but the basic idea only takes three lines of code:

    $post_types = get_post_types( array( 'public' => true, 'exclude_from_search' => false ), 'objects' );
    foreach ( $post_types as $type )

    Rather than the plugin registering the meta box for just pages or just posts, it could loop through the available post types and register its meta box.

    Firstly, thank you Microkid for a great plugin. I hope you dont mind me posting this fix for CPT and perhaps you could use it to update the next version 🙂

    whipd09, I have found a hack to satisfy your #1 request until it makes it into the plug-in.
    In the microkids-related-posts.php
    I changed the following:

    1. change: function MRP_add_custom_box() {
    add_meta_box( ‘MRP_sectionid’, __( ‘Related Posts’, ‘MRP_textdomain’ ), ‘MRP_inner_custom_box’, ‘post’, ‘normal’ );//remove this line if you dontwant it to show in normal posts
    add_meta_box( ‘MRP_sectionid’, __( ‘Related Posts’, ‘MRP_textdomain’ ), ‘MRP_inner_custom_box’, ‘archives’, ‘normal’ );//change archives to the name of your custom post type. You could also add more types by copying this line for each type.

    2.function MRP_inner_custom_box() {
    change: if( $related_post->post_type == ‘page’ ) { to if( $related_post->post_type == ‘archive’ ) {

    3. change $post_title = “[Page] ” . $post_title; to $post_title = “[Archive] ” . $post_title;

    4. function MRP_save_postdata( $post_id ) {

    change: if ( ‘page’ == $_POST[‘post_type’] ) { to if ( ‘archives’ == $_POST[‘post_type’] ) {

    5. function MRP_auto_related_posts( $content ) {
    if( get_post_type() == ‘page’ ) { to if( get_post_type() == ‘archives’ ) {

    Lastly in mrp-search.php, change:
    $query = “SELECT ID, post_title, post_type, post_status FROM $wpdb->posts WHERE $where AND ( post_type = ‘archives’ OR post_type = ‘page’ ) “; to your post type.

    Hope it helps someone.

    Edit: I also added this into admin_init() function in my custom functions file when registering the CPT: add_meta_box( ‘MRP_sectionid’, __( ‘Related Links’, ‘MRP_textdomain’ ), ‘MRP_inner_custom_box’, ‘archives’, ‘normal’ );

    Hi whipd09,

    I have just released version 3.0 of my plugin. Apart from a bunch of other cool new features, this version also adds support for custom post types. You can update it through your WordPress admin or read more about the new version on the Microkids Related Posts plugin website

    Check it out and let me know what you think!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Custom Post Types and Plugins’ is closed to new replies.