Related Posts for WordPress
Plugin doesn't work with related custom post types (1 post)

  1. imero
    Posted 2 years ago #

    I tried to retrieve related custom post types for a post using MRP_get_related_posts function but failed. The function didn't return anything.

    What I did according to docs:

    //Create array with custom post types
    $post_type = array('book', 'game', 'movie');
    //Invoke function
    $related_posts = MRP_get_related_posts($post->ID, false, true, $post_type);

    After that $related_posts variable remained empty. I found that in the plugin grouped custom post types are retrieved with SQL function which ends with [...AND wp.post_type IN (".implode( ",", $post_type ).") "]. In case of my example the SQL-statement transforms into [...AND wp.post_type IN (book, game, movie)] yet it should actually be [...AND wp.post_type IN ('book', 'game', 'movie')]. So, taking that into account I tried to add quotes in my code and it worked! The new code looks so:

    //Create array with custom post types
    $postTypes = array("'book'", "'game'", "'movie'");

    Ok, my code started to work smoothly but I think it's not very convenient to use quotes inside quotes and also it doesn't conform to what is said about using this function in plugin docs. I think we need some clarification on this issue.


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Related Posts for WordPress
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic