Posts 2 Posts
pass arguments to get_related (2 posts)

  1. joostvanhoof
    Posted 2 years ago #

    First of all; scribu this plugin rocks! It really helps with my project in which I have hundreds of events, tens of genres and thousands of artists.

    I link genres to events and use get_related to find events that are related to the same genres. But I've noticed that the get_related method outputs 10 related posts. Since I have hundreds of events, I'd like to display more.

    Is there a way to pass arguments, in this case 'posts_per_page'(like in wp_query) to get_related? Or is there another way to alter the number of results the get_results method outputs?



  2. joostvanhoof
    Posted 2 years ago #

    I found the solution after reading this post.

    In wp-content/plugins/posts-to-posts/core/directed-connection-type.php I've added:

    public function my_get_related( $item, $extra_qv = array(), $output = 'raw' ) {
    		$extra_qv['fields'] = 'ids';
    		$connected = $this->get_connected( $item, $extra_qv, 'abstract' );
    		$additional_qv = array( 'p2p:exclude' => _p2p_normalize( $item ), 'posts_per_page' => -1 );
    		return $this->flip_direction()->get_connected( $connected->items, $additional_qv, $output );

    This works perfectly. But I'd like to declare this function in functions.php instead of in the p2p core since that could backfire when updating the plugin.

    I've tried adding public function ... to functions.php and add_action('p2p_init', 'my_get_connected') but that doesn't seem to work. Anyone has an idea how to declare this function outside of the core?


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Posts 2 Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic