WordPress.org

Support

Support » Plugins and Hacks » Posts 2 Posts » Filter post type archive by connection to specific post from another connected p

Filter post type archive by connection to specific post from another connected p

  • I have two post type $post_type_a and $post_type_b connected using a many to may relationship. On the $post_type_a archive page I want to filter the archive to display ONLY the posts that are connected to a specific post of $post_type_b preferably using pre_get_posts() to set the query_vars on the specific post type archive

    Real world example:
    Two post types: Books, Publishers
    On the Books archive I want to display ONLY those posts that are connect to a specific Publisher (eg. Random House). So any book that is connected to another publisher another than Random House would NOT be displayed on the Books Archive Page

    http://wordpress.org/extend/plugins/posts-to-posts/

Viewing 1 replies (of 1 total)
  • I’m trying to achieve something similar, but with no luck yet.

    I tried modifiying the $query with pre_get_posts like this

    function create_press_archives_per_staging( $query ) {
        if ( $query->is_post_type_archive('press') && $query->is_main_query() ) {
    
            $query->set( 'connected_type', 'press_with_stagings' );
            // hard-coded post-ID is just for testing purposes
            $query->set( 'connected_items', get_post('1609') );
        }
    }
    add_action( 'pre_get_posts', 'create_press_archives_per_staging' );

    Would be nice if someone could bump me into the right direction 😉

Viewing 1 replies (of 1 total)
  • The topic ‘Filter post type archive by connection to specific post from another connected p’ is closed to new replies.
Skip to toolbar