最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp query - How to filter, restrict and return posts based on custom user meta information

programmeradmin4浏览0评论

On this online platform project i have requested all users to add in their school title.

In the user dashboard there is a posts section which currently shows all posts. I want to only show posts that belong to users from the same school or institute.

I am working in the child theme and have possibly found out i would need:

add_filter( 'hook_into_theme', 'my_posts_filter');

I also understand, may be wrong, that i would need an array possibly. So the key is institute : value (whatever the users put it as)

$args = array(
      'meta_query' => array(
                                array(
                                 'key' => 'school',
                                 'value' => $??? what do i put here $current_user->ID,
                                 'compare' => '='
                                )
                            ) 
            );

How would i combine the function and the array to work to filter posts to only show those from the same school??

Here is my try:

    add_filter( 'theme_customisation_hook', 'my_posts_filter');
function my_posts_filter ($args) {
$args = array(
      'meta_query' => array(
                                array(
                                 'key' => 'school',
                                 'value' => $current_user->ID,
                                 'compare' => '='
                                )
                            ) 
            );
}

Does this make any sense?

发布评论

评论列表(0)

  1. 暂无评论