The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Posts 2 Posts
Filter connectabl posts by category (6 posts)

  1. waltervos
    Posted 5 years ago #


    Is it possible to filter the available posts in the Posts 2 posts meta box by category? What I would like is to register a connection to 'posts', but only posts in a certain category.

    Does this plugin have a filter at the point where the available posts (to connect to) are fetched?

    - Walter

  2. scribu
    Plugin Author

    Posted 5 years ago #

    Here's how you can do it in the development version (0.4.1-alpha):

    function my_connection_types() {
    	if ( !function_exists('p2p_register_connection_type') )
    	class My_P2P_Box extends P2P_Box_Multiple {
    		function get_search_args( $search ) {
    			$args = parent::get_search_args( $search );
    			$args['category_name'] = 'some-category';
    			return $args;
    	p2p_register_connection_type( array(
    		'from' => 'ptype_a',
    		'to' => 'ptype_b',
    		'box' => 'My_P2P_Box'
    	) );
    add_action('init', 'my_connection_types', 100);

    The above code goes in your theme's functions.php file.

  3. waltervos
    Posted 5 years ago #

    Thanks Scribu, that should work just fine!

  4. Israel Curtis
    Posted 5 years ago #

    I was hoping to adapt this to restrict the posts that appear in the meta box to only those that are "published", whereas currently p2p doesn't seem to care what the status is. I changed the $args to

    $args['post_status'] = 'publish';

    but I see no difference in the meta box search results - I'm still getting matches for draft posts...

    What am I missing?

  5. Israel Curtis
    Posted 5 years ago #

    ugh - thought I had the 0.4.1-alpha enabled, but was actually using 0.4

    but - when I installed 0.4.1-alpha, nothing at all would appear in the p2p search results. With or without the new My_P2P_Box class. Didn't change anything else about my p2p setup - just updated to 0.4.1-alpha, so kind of hard to tell if this My_P2P_Box class works with post_status...

    did something else change with 0.4.1-alpha?


  6. scribu
    Plugin Author

    Posted 5 years ago #

    Please try re-downloading the development version now.

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