0

I have two custom post types registered.

  1. Custom Post Type: PUBLIKATIONEN with the two custom taxonomies LISTEN and AUTOREN
  2. Custom Post Type: AUTOREN

Both have archives.

With: <?php echo get_post_type_archive_link( 'writers' ); ?> I can list all posts of the Custom Post Type AUTOREN (= writer's profiles) on a PUBLIKATIONEN post. But what I want to do is to list only the posts of the writers who have contributed to a certain publication.

Basically it's like this

  1. Custom Post Type:

    • PUBLIKATIONEN = Custom Post Type
    • AUTOREN = Taxonomy
    • Name = Term
  2. Custom Post Type:

    • AUTOREN = Custom Post Type
    • Name = Terms (no Taxonomy)

So I need to fetch the terms of the PUBLIKATIONEN post and list them as post under AUTOREN Custom Post Type using a specific template (single-autoren.php).

This is what I have come up with so far, but really no idea how to set this up properly:

//Get Autoren Posts
function get_post_type_archive_link_custom( $myquery ) {

    $myquery['tax_query'] = array(
        'relation' => 'AND',
        array(
            'post_type' => 'publikationen', 
            'taxonomy' => 'autoren',
            'terms' => array('autoren'),
            'field' => 'slug',
        ),
        array(
            'post_type' => 'autoren',   
            'terms' => array('autoren'),
            'field' => 'slug',
        ),
    );

    query_posts($myquery);

    wp_reset_query();
}
add_action( 'pre_get_posts', 'get_post_type_archive_link_custom' );

Any ideas greatly appreciated!

  • Why do you have a custom post type and a custom taxonomy of writer? – gdaniel Jan 17 '15 at 3:46
  • Because the custom post type WRITERS is for posts (writer's profiles) and the custom taxonomy assigned to CPT PUBLICATIONS is for selecting which writers have contributed to a certain publication. Basically the whole CPT thing is to make it easy for the customer to enter data, but if I had known that CPT's is not just another version of categories and tags I would've gone down the category & tags road. – gfaw Jan 17 '15 at 8:53
  • I think that Post 2 Post would be a better solution for you. Removes the proxy Writers taxonomy. This plugin is written by some big names in WP, so it's a trusted tool for sure. wordpress.org/plugins/posts-to-posts – Eric Holmes Jan 19 '15 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.