如果按POST_FORMAT排除,则上一个POST_LINK/NEXT_POST_LINK消失

时间:2015-06-29 作者:markshiz

我试图从我的下一个和上一个链接中排除其他帖子格式,但出于某些原因,使用get_term_by 不会把term_id 对于post_format 分类学我看到Wordpress核心正在使用这种分类法here, 所以我知道我这样做是对的。根据this posting, 我需要确保分类法已正确注册。打印调试我从中看到以下输出get_taxonomies().

Array
(
    [category] => category
    [post_tag] => post_tag
    [nav_menu] => nav_menu
    [link_category] => link_category
    [post_format] => post_format
    [tagportfolio] => tagportfolio
)
这样我就能看到post_format 分类法已注册。这是我的代码:

<?php print_r(get_taxonomies()); ?>
<?php print_r(get_term_by(\'id\', \'post-format-aside\', \'post_format\')->term_id); ?>
<?php previous_post_link(\'&lsaquo; %link\', \'%title\', false, array(get_term_by(\'id\', \'post-format-aside\', \'post_format\')->term_id )); ?>
<?php next_post_link(\'%link &rsaquo;\', \'%title\', false, array(get_term_by(\'id\', \'post-format-aside\', \'post_format\')->term_id )); ?>
你知道为什么这样不行吗?为什么这里不排除旁白?

UPDATE 1

下面的代码从中返回term\\u idget_term_by, 但会导致下一个/上一个链接消失:

<?php print_r(get_taxonomies()); ?>
<?php print_r(get_term_by(\'slug\', \'post-format-aside\', \'post_format\')->term_id); ?>
<?php previous_post_link(\'&lsaquo; %link\', \'%title\', false, array(get_term_by(\'slug\', \'post-format-aside\', \'post_format\')->term_id )); ?>
<?php next_post_link(\'%link &rsaquo;\', \'%title\', false, array(get_term_by(\'slug\', \'post-format-aside\', \'post_format\')->term_id )); ?>
返回的对象get_term_by 是:

STDCLASS OBJECT ( [TERM_ID] => 10 [NAME] => ASIDE [SLUG] => POST-FORMAT-ASIDE [TERM_GROUP] => 0 [TERM_TAXONOMY_ID] => 10 [TAXONOMY] => POST_FORMAT [DESCRIPTION] => [PARENT] => 0 [COUNT] => 0 [FILTER] => RAW )

UPDATE 2

当我启用Wordpress query debugging, 我看到下面的查询被触发,它是空集。

mysql> SELECT P.ID FROM WP_POSTS AS P INNER JOIN WP_TERM_RELATIONSHIPS AS TR ON P.ID = TR.OBJECT_ID INNER JOIN WP_TERM_TAXONOMY TT ON TR.TERM_TAXONOMY_ID = TT.TERM_TAXONOMY_ID WHERE P.POST_DATE < \'2015-06-01 20:10:00\' AND P.POST_TYPE = \'PROJECT\' AND TT.TAXONOMY = \'CATEGORY\' AND P.ID NOT IN ( SELECT TR.OBJECT_ID FROM WP_TERM_RELATIONSHIPS TR LEFT JOIN WP_TERM_TAXONOMY TT ON (TR.TERM_TAXONOMY_ID = TT.TERM_TAXONOMY_ID) WHERE TT.TERM_ID IN (10) ) AND ( P.POST_STATUS = \'PUBLISH\' OR P.POST_STATUS = \'PRIVATE\' ) ORDER BY P.POST_DATE DESC ;

Empty set (0.01 sec)
上述内容的奇怪之处在于,查询似乎试图根据类别分类法查找上一篇文章,我已明确要求函数不要通过查询参数执行此操作。在我看来,这似乎是Wordpress中的一个bug。

1 个回复
最合适的回答,由SO网友:markshiz 整理而成

我对Wordpress提出了一个bug,因为这里的查询让我相信这是框架中的bug:https://core.trac.wordpress.org/ticket/32833#ticket

结束

相关推荐