admin管理员组

文章数量:1130349

How to display particular categorie's post which associated to specific user?

/

Above link displays all the posts under fish category, but how can I display only the posts which are under fish category and particular user also.

Is there any URL like above which displays user specific posts? It can be with User ID.

How to display particular categorie's post which associated to specific user?

http://tugsemegtei.mn/category/fish/

Above link displays all the posts under fish category, but how can I display only the posts which are under fish category and particular user also.

Is there any URL like above which displays user specific posts? It can be with User ID.

Share Improve this question asked Nov 9, 2018 at 18:29 anandmongolanandmongol 1371 gold badge2 silver badges13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

How are you associating users to a post? If you meant users as post authors you can try pre_get_posts hook.

function user_author_pre_get_posts( $query ) {
    $user_id = get_current_user_id(); // Get logged in user ID or pass specific user ID here
  if ( ( $query->is_author() || $query->is_category() ) && $query->is_main_query() ) {
        $query->set( 'author__in', $user_id );
  }
}
add_action( 'pre_get_posts', 'user_author_pre_get_posts' );

How to display particular categorie's post which associated to specific user?

/

Above link displays all the posts under fish category, but how can I display only the posts which are under fish category and particular user also.

Is there any URL like above which displays user specific posts? It can be with User ID.

How to display particular categorie's post which associated to specific user?

http://tugsemegtei.mn/category/fish/

Above link displays all the posts under fish category, but how can I display only the posts which are under fish category and particular user also.

Is there any URL like above which displays user specific posts? It can be with User ID.

Share Improve this question asked Nov 9, 2018 at 18:29 anandmongolanandmongol 1371 gold badge2 silver badges13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

How are you associating users to a post? If you meant users as post authors you can try pre_get_posts hook.

function user_author_pre_get_posts( $query ) {
    $user_id = get_current_user_id(); // Get logged in user ID or pass specific user ID here
  if ( ( $query->is_author() || $query->is_category() ) && $query->is_main_query() ) {
        $query->set( 'author__in', $user_id );
  }
}
add_action( 'pre_get_posts', 'user_author_pre_get_posts' );

本文标签: How to display particular categorie39s post which associated to specific user