隐藏帖子(如果添加了用户)

时间:2019-09-03 10:49:27

标签: php sql wordpress

我在wordpress中有此帖子列表。我做了一个收藏夹功能,当您将某件商品标记为收藏夹时,它会添加到该行的开头。这里的问题是我在这2个地方跑。一个顶部面板显示了我喜欢的我喜欢的帖子,然后第二个帖子显示了来自其他用户的我喜欢的帖子。顶部面板工作正常。.但是问题是我的个人资料卡片显示在第二个面板中,其他用户卡片显示在这里: https://gyazo.com/75cf45a0844cba1f9ca6818e059d8bf6

如您所见,第二个面板中有一个重复项。如何使用WP_Query摆脱它?

用户位于带有ACF字段的多用户字段中。

我尝试做各种事情,例如AND和OR。我很可能会找到解决方案,但似乎找不到解决方法。

TOP面板代码:

$aProjectArgs = array(
        'post_type' => 'project',
        'post_status'=> 'publish',
        'posts_per_page'=> -1,
        'orderby'   => 'favorit_users',
        'order'   => 'DESC',
        'meta_query' => array(
            'relation' => 'OR',
                array(
                    'relation' => 'OR',
                    array(
                        'key' => 'project_users',
                        'value' => get_current_user_id(),
                        'compare' => '='
                    ),
                    array(
                        'key' => 'project_users', // name of custom field
                        'value' => '"'.get_current_user_id().'"',
                        'compare' => 'LIKE'
                    ),
                ),
                array(
                    'relation' => 'AND',
                    array(
                        'relation' => 'OR',
                        array(
                            'key' => 'project_users',
                            'value' => get_current_user_id(),
                            'compare' => '='
                        ),
                        array(
                            'key' => 'project_users', // name of custom field
                            'value' => '"'.get_current_user_id().'"',
                            'compare' => 'LIKE'
                        ),
                    ),
                    "favorit_users" => array(
                        'key' => 'favorite_users',
                        'value' => get_current_user_id(), 
                        'compare' => 'LIKE'
                    ),
                ),
            ),
        );
    $aProjectQuery = new WP_Query($aProjectArgs);

第二个面板(下):

$allProjectArgs = array(
        'post_type' => 'project',
        'post_status'=> 'publish',
        'posts_per_page'=> -1,
        'orderby'   => 'favorit_users',
        'order'   => 'DESC',
        'meta_query' => array(
            'relation' => 'OR',
                array(
                    'relation' => 'OR',
                    array(
                        'key' => 'project_users',
                        'value' => get_current_user_id(),
                        'compare' => '!='
                    ),
                    array(
                        'key' => 'project_users',
                        'value' => '"'.get_current_user_id().'"',
                        'compare' => 'NOT LIKE'
                    ),
                    array(
                        'key' => 'favorite_users',
                        'compare' => 'NOT EXISTS'
                    ),
                ),
                "favorit_users" => array(
                    'key' => 'favorite_users',
                    'value' => $iCurrentUserID, 
                    'compare' => 'LIKE'
                ),
            ),
        );
    $allProjectQuery = new WP_Query($allProjectArgs);

最后,重复项应隐藏在第二个面板中。我附属的几乎每张卡都应该隐藏。如果与我的用户无关,则带有我最喜欢的(星号)的卡片应保留。

0 个答案:

没有答案