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 badges1 Answer
Reset to default 0How 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 badges1 Answer
Reset to default 0How 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
版权声明:本文标题:How to display particular categorie's post which associated to specific user? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749194387a2330648.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论