WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
Filter post type archive by connection to specific post from another connected p (2 posts)

  1. Chris Moguel
    Member
    Posted 1 year ago #

    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/

  2. Carsten Bach
    Member
    Posted 1 year ago #

    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 ;)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic