Posts 2 Posts
[resolved] P2P - Limiting results in admin meta box to fit certain criteria (3 posts)

  1. RiseOfLex88
    Posted 2 years ago #

    Using Scribu's AMAZING posts to posts plugin I have two custom post types - Races and Drivers - each race has a result where 22 drivers are connected to the race post.

    The issue I have is that there are 100+ drivers available, but only 22 are actually in the racing series so it's only ever those 22 I want to choose from.

    Is there a way to limit the p2p search results in the admin meta box based on the meta data?


    P.s. apologies for duplicate post, posted in wrong place first.

  2. scribu
    Plugin Author

    Posted 2 years ago #

    Yes, when calling p2p_register_connection_type(), you can pass either 'to_query_vars' or 'from_query_vars' to filter the candidates.

    Or, you can use the 'p2p_connectable_args' filter:


  3. RiseOfLex88
    Posted 2 years ago #

    Brilliant, thanks. Took a little bit of hunting but you set me on the right path. For anyone else this is what I've done...

    'to_query_vars' => array(
    			'meta_key' => 'driver_2013_number',
    			'meta_value' => ''

    so full registration is...

    p2p_register_connection_type( array(
    		'name' => 'race_results',
    		'from' => 'races',
    		'to' => 'drivers',
    		'to_query_vars' => array(
    			'meta_key' => 'driver_2013_number',
    			'meta_value' => ''
    		'title'       => 'Race Results',
    		'cardinality' => 'many-to-many',
    	) );

    This looks for any posts in the 'drivers' post type with the 'driver_2013_number' meta entered i.e. only drivers competing this year.

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