如何在WordPress中总是在顶部(在常规帖子之前)显示粘滞帖子?

时间:2019-04-02 作者:user5447339

我正在编写一个wordpress代码,如下所示modified post displays at the top.

$temp_args = [
    \'post_type\' => array(\'current-channel\', \'post\', \'current-episodes\'),
    \'post_status\' => \'publish\',
    \'orderby\' => array(
        \'feat_yes\' => \'ASC\',
        \'post_type\' => \'ASC\',
        \'modified\' => \'DESC\',
        \'date\' => \'DESC\'),
    \'posts_per_page\' => $data->{"no_articles_" . ICL_LANGUAGE_CODE},
    \'tax_query\' => [
        [
            \'taxonomy\' => \'category\',
            \'field\' => \'term_id\',
            \'terms\' => $cat_today,
        ],
    ],

];
$q = new WP_Query($temp_args);
此时,按以下方式进行订购:

\'orderby\' => array(
    \'feat_yes\' => \'ASC\',
    \'post_type\' => \'ASC\',
    \'modified\' => \'DESC\',
    \'date\' => \'DESC\'),  

Problem Statement:

我想知道我应该在上面的代码中做些什么更改,以便sticky posts are displayed at the top before the regular post.

订单应该是这样的sticky post should be always at the top 然后all the regular post

1 个回复
SO网友:admcfajn

我想您可能需要添加feat_yes 作为meta_key

$temp_args = [
    \'post_type\' => array(\'current-channel\', \'post\', \'current-episodes\'),
    \'post_status\' => \'publish\',
    \'meta_key\' => \'feat_yes\',
    \'orderby\' => array(
        \'meta_value_num\' => \'ASC\', /* or \'meta_value\' */
        \'post_type\' => \'ASC\',
        \'modified\' => \'DESC\',
        \'date\' => \'DESC\'),
    \'posts_per_page\' => $data->{"no_articles_" . ICL_LANGUAGE_CODE},
    \'tax_query\' => [
        [
            \'taxonomy\' => \'category\',
            \'field\' => \'term_id\',
            \'terms\' => $cat_today,
        ],
    ],

];
$q = new WP_Query($temp_args);
以下是一些相关链接:

相关推荐

PHP:对REST请求进行身份验证?

我确实使用REST api为正在开发的插件创建了一些自定义端点。它工作得很好,但现在我想保护这些请求:我不需要外部用户(EDIT: 我指的是远程请求),以便能够进行查询。但我只找到有关javascript身份验证的文档(REST API Handbook).如何使用PHP实现身份验证(此处为WP 5.1.1)?谢谢