admin管理员组文章数量:1434949
On my developer site this query is used for a carousel in index.php :
$vedette_accueil = new WP_Query(array(
'tag' => 'vedette-accueil',
'nopaging' => true,
'post_type' => array('post','mensuels')
));
mensuels
is a simple custom post type with post abilities and uses the post_tag
taxonomy. it is used to present a few articles of particular interest - described in a paragraph - for a given month.
It works as intended. It shows up in the carousel as intended.
On the production server, my cpt does not show up in the carousel. Every thing else about it works just fine: its pages work, it's there in the tab assigned to it in the index page, but just won't show up in the carousel. I even do a wp_reset_postdata()
between queries.
The only difference between implementations is that I named it themes_mensuels
rather than mensuels
. that's it. I pick the tag from the list, I can see it stick to my cpt because I have proper results in admin:
[mysite.ca]/wp-admin/edit.php?post_type=themes_mensuels&tag=vedette-accueil
Here are the first few lines of var_dumps
of the query. First, DEV (that works):
object(WP_Query)#11489 (49) {
["query"]=>
array(3) {
["tag"]=>
string(15) "vedette-accueil"
["nopaging"]=>
bool(true)
["post_type"]=>
array(2) {
[0]=>
string(4) "post"
[1]=>
string(8) "mensuels"
}
}
["query_vars"]=>
array(64) {
["tag"]=>
string(15) "vedette-accueil"
["nopaging"]=>
bool(true)
["post_type"]=>
array(2) {
[0]=>
string(4) "post"
[1]=>
string(8) "mensuels"
}
Here is PROD:
object(WP_Query)#10593 (49) {
["query"]=>
array(3) {
["tag"]=>
string(15) "vedette-accueil"
["nopaging"]=>
bool(true)
["post_type"]=>
array(2) {
[0]=>
string(15) "themes_mensuels"
[1]=>
string(4) "post"
}
}
["query_vars"]=>
array(64) {
["tag"]=>
string(15) "vedette-accueil"
["nopaging"]=>
bool(true)
["post_type"]=>
array(2) {
[0]=>
string(4) "post"
[1]=>
string(4) "page"
}
The funny thing is that i can query "just" the post type and see the few I have in the carousel. But when I add the tag, it just bumps the cpt.
I did a bit of research and the naming seems conventional. I added the recommendation from here.
but to no avail.
What very subtle WP idiosyncrasy am I missing??
On my developer site this query is used for a carousel in index.php :
$vedette_accueil = new WP_Query(array(
'tag' => 'vedette-accueil',
'nopaging' => true,
'post_type' => array('post','mensuels')
));
mensuels
is a simple custom post type with post abilities and uses the post_tag
taxonomy. it is used to present a few articles of particular interest - described in a paragraph - for a given month.
It works as intended. It shows up in the carousel as intended.
On the production server, my cpt does not show up in the carousel. Every thing else about it works just fine: its pages work, it's there in the tab assigned to it in the index page, but just won't show up in the carousel. I even do a wp_reset_postdata()
between queries.
The only difference between implementations is that I named it themes_mensuels
rather than mensuels
. that's it. I pick the tag from the list, I can see it stick to my cpt because I have proper results in admin:
[mysite.ca]/wp-admin/edit.php?post_type=themes_mensuels&tag=vedette-accueil
Here are the first few lines of var_dumps
of the query. First, DEV (that works):
object(WP_Query)#11489 (49) {
["query"]=>
array(3) {
["tag"]=>
string(15) "vedette-accueil"
["nopaging"]=>
bool(true)
["post_type"]=>
array(2) {
[0]=>
string(4) "post"
[1]=>
string(8) "mensuels"
}
}
["query_vars"]=>
array(64) {
["tag"]=>
string(15) "vedette-accueil"
["nopaging"]=>
bool(true)
["post_type"]=>
array(2) {
[0]=>
string(4) "post"
[1]=>
string(8) "mensuels"
}
Here is PROD:
object(WP_Query)#10593 (49) {
["query"]=>
array(3) {
["tag"]=>
string(15) "vedette-accueil"
["nopaging"]=>
bool(true)
["post_type"]=>
array(2) {
[0]=>
string(15) "themes_mensuels"
[1]=>
string(4) "post"
}
}
["query_vars"]=>
array(64) {
["tag"]=>
string(15) "vedette-accueil"
["nopaging"]=>
bool(true)
["post_type"]=>
array(2) {
[0]=>
string(4) "post"
[1]=>
string(4) "page"
}
The funny thing is that i can query "just" the post type and see the few I have in the carousel. But when I add the tag, it just bumps the cpt.
I did a bit of research and the naming seems conventional. I added the recommendation from here.
but to no avail.
What very subtle WP idiosyncrasy am I missing??
Share Improve this question edited Apr 5, 2019 at 16:48 Qaisar Feroz 2,1471 gold badge9 silver badges20 bronze badges asked Apr 3, 2019 at 19:00 SassinakSassinak 216 bronze badges 12- Can you spot something in debug.log? – middlelady Commented Apr 3, 2019 at 19:12
- 1 Now is the right time to learn how to use it. Will get back with info – Sassinak Commented Apr 3, 2019 at 19:56
- Is this supposed to do anything: define( 'SAVEQUERIES', true ); cause I have unrelated errors so far. – Sassinak Commented Apr 3, 2019 at 20:48
- I will rename my CPT to be the same as in DEV. If that helps, I will be disappoint in WP for such a silly fault – Sassinak Commented Apr 4, 2019 at 15:18
- well, it was a lot of messing about, and the cpt is now named "mensuels" just like it is in dev, Everything works as expected EXCEPT it STILL won't appear in the carousel. I furthered my research by closely comparing the var_dumps of both DEV and Prod. Apart from the result, no other differences show up. – Sassinak Commented Apr 4, 2019 at 19:55
1 Answer
Reset to default 1I ended up using
'tag_slug__in'=>array( 'vedette-accueil'),
and now it works. How this is different from
'tag' => 'vedette-accueil',
and how the later would transform the query so that the cpt was ignored, I may never know...but I would love it if someone told me.
本文标签: custom post typesCan39t query tag and posttype at the same time
版权声明:本文标题:custom post types - Can't query tag and post_type at the same time 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745623714a2666841.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论