Support » Plugin: Posts 2 Posts » [Plugin: Posts 2 Posts] Filter connectabl posts by category

  • Hi,

    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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author scribu

    (@scribu)

    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') )
    	        return;
    
    	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.

    Thanks Scribu, that should work just fine!

    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?

    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?

    😉

    Plugin Author scribu

    (@scribu)

    Please try re-downloading the development version now.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Posts 2 Posts] Filter connectabl posts by category’ is closed to new replies.