0

I have 2 custom post types. Let's call them: CPT1 = movies CPT2 = actors

When on the admin CPT post list, clicking on the author name gets me to:

edit.php?post_type=movies&author=5

This displays the correct posts.

Now when I try this in the 2nd CPT:

edit.php?post_type=actors&author=5

It doesn't work, it displays the posts for movies CPT

0

You can try this code

<?php
add_action( 'restrict_manage_posts', 
'admin_posts_filter_restrict_manage_posts_by_author' );
/**
 * Create the drop down
 *
 * @return void
 */
function admin_posts_filter_restrict_manage_posts_by_author(){
if (isset($_GET['post_type']) && 'task' == $_GET['post_type']){
    wp_dropdown_users( array(
        'show_option_all' => __( 'Show All Authors', 'your-site' ),
        'name' => 'bcust_id',
        'selected' => $_GET['bcust_id']
    ));
  }
}
add_filter( 'parse_query', 'modify_query_to_filter_by_author' );
/**
 * Filter by author
 * @param  (wp_query object) $query
 *
 * @return Void
 */
function modify_query_to_filter_by_author( $query ){
global $pagenow;
if ( isset($_GET['post_type']) 
     && 'task' == $_GET['post_type'] 
     && is_admin() && 
     $pagenow == 'edit.php' 
     && isset($_GET['bcust_id']) 
     && $_GET['bcust_id'] != '') {
    $query->query_vars['author'] = $_GET['bcust_id'];
  }
}
  • I think this will make posts only editable by its author, which isn't what I wanted. What I'm after is when your on the admin post list and you click the author of one of the posts, it displays all posts by that author. This works on one cpt but doesn't work on the other. – bad boy Oct 3 '18 at 12:10

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.