admin管理员组文章数量:1026989
I am working on a wordpress code as shown below in which the 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);
At this moment, order by is done in the following way:
'orderby' => array(
'feat_yes' => 'ASC',
'post_type' => 'ASC',
'modified' => 'DESC',
'date' => 'DESC'),
Problem Statement:
I am wondering what changes I should make in the code above so that sticky posts are displayed at the top before the regular post.
The order should be in a way that sticky post should be always at the top and then all the regular post
I am working on a wordpress code as shown below in which the 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);
At this moment, order by is done in the following way:
'orderby' => array(
'feat_yes' => 'ASC',
'post_type' => 'ASC',
'modified' => 'DESC',
'date' => 'DESC'),
Problem Statement:
I am wondering what changes I should make in the code above so that sticky posts are displayed at the top before the regular post.
The order should be in a way that sticky post should be always at the top and then all the regular post
Share Improve this question edited Apr 2, 2019 at 2:43 user5447339 asked Apr 2, 2019 at 2:18 user5447339user5447339 819 bronze badges1 Answer
Reset to default 0I think you may need to add the feat_yes
as a 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);
Here's a few relevant links:
- https://codex.wordpress/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
- WP_Query - Order results by meta value
- Custom query with orderby meta_value of custom field
I am working on a wordpress code as shown below in which the 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);
At this moment, order by is done in the following way:
'orderby' => array(
'feat_yes' => 'ASC',
'post_type' => 'ASC',
'modified' => 'DESC',
'date' => 'DESC'),
Problem Statement:
I am wondering what changes I should make in the code above so that sticky posts are displayed at the top before the regular post.
The order should be in a way that sticky post should be always at the top and then all the regular post
I am working on a wordpress code as shown below in which the 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);
At this moment, order by is done in the following way:
'orderby' => array(
'feat_yes' => 'ASC',
'post_type' => 'ASC',
'modified' => 'DESC',
'date' => 'DESC'),
Problem Statement:
I am wondering what changes I should make in the code above so that sticky posts are displayed at the top before the regular post.
The order should be in a way that sticky post should be always at the top and then all the regular post
Share Improve this question edited Apr 2, 2019 at 2:43 user5447339 asked Apr 2, 2019 at 2:18 user5447339user5447339 819 bronze badges1 Answer
Reset to default 0I think you may need to add the feat_yes
as a 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);
Here's a few relevant links:
- https://codex.wordpress/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
- WP_Query - Order results by meta value
- Custom query with orderby meta_value of custom field
本文标签: phpHow to display sticky post always at the top (before regular post) in wordpress
版权声明:本文标题:php - How to display sticky post always at the top (before regular post) in wordpress? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745637817a2160557.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论