Support » Plugin: Posts 2 Posts » filtering results by tags

  • I’m running a complicated query…or at least trying to! I may have the wrong idea on how this plugin works, but here goes.

    I have a custom post type called People (slug ‘people’)
    I have a second custom post type called Events (slug ‘events’)
    The Events CPT has a custom taxonomy associated with it called Features (slug “featurestax”)
    One of the tags in Features is named “Featured” (slug is “is-featured”) used to identify if a given event should be on a custom page called “Featured Events.”

    What I need to do is get the following:
    “Show me all Events (custom post type) tagged as “Featured” in “Features” (custom taxonomy) that are linked to a given person from the People (custom post type).”

    For example: Show me all events tagged as is-featured that are linked to Mike.

    I previously solved tis problem by creating a second custom taxonomy called People (slug ‘person’) that had the same content as the People custom post type. I used this to get the posts in question:

    $opts = array(
    	'post_type' => 'events',
    	'featurestax' => 'is-featured',
    	'person' => '123',
    	'order' => 'DSC',
    	'orderby' => 'date',

    This works, but it meant duplicating the People custom post type as a custom taxonomy under Events which is what I’m trying to undo with the posts 2 posts plugin.

    I have created the link in functions using the example:

    function my_connection_types() {
    	p2p_register_connection_type( array(
    		'name' => 'people_to_events',
    		'from' => 'people',
    		'to' => 'events',
            'sortable'   => 'any',
            'reciprocal' => true,
    	) );
    add_action( 'p2p_init', 'my_connection_types' );

    After doing this, I have connected a few Events to a few People int eh GUI, which all works fine.

    However I can’t figure out how to call the actual query. In the custom template in which it’s being called, I have

    $opts = array(
    	'connected_type' => 'people_to_events',
    	'connected_items' => get_queried_object(),
    $query = new WP_Query($opts);
    if ($query->have_posts() ) {the_title('<h1>', '</h1>');}
    else { echo 'No Posts Found';}

    for which I get the string “No Pages Found” so even without filtering by the custom taxonomy it’s clearly not working. Can anyone direct me on what I should be doing instead?

    Can this plugin do what I’m after?


  • The topic ‘filtering results by tags’ is closed to new replies.