WordPress 通过自定义分类法获取自定义文章类型的相关文章

有时候我们需要为网站添加一个自定义文章类型,但是当访问此文章类型页面时,如何获取相关联的文章呢?请看以下代码:

$terms = get_the_terms($post->ID, 'product_tags', 'string');  $term_ids = wp_list_pluck($terms, 'term_id');    $second_query = new WP_Query(array(      'post_type' => 'products',      'tax_query' => array(          array(              'taxonomy' => 'product_tags',              'field' => 'id',              'terms' => $term_ids,              'operator' => 'IN' //Or 'AND' or 'NOT IN'          )      ),      'posts_per_page' => 3,      'ignore_sticky_posts' => 1,      'orderby' => 'rand',      'post__not_in' => array($post->ID)  ));    if ($second_query->have_posts()) {      while ($second_query->have_posts()) : $second_query->the_post();      //loop      endwhile;      wp_reset_query();  }

腾讯云限时秒杀【点击购买】

搬瓦工,CN2高速线路,1GB带宽,电信联通优化KVM,延迟低,速度快,建站稳定,搬瓦工BandwagonHost VPS优惠码BWH26FXH3HIQ,支持<支付宝> 【点击购买】!

Vultr$3.5日本节点,512M内存/500G流量/1G带宽,电信联通优化,延迟低,速度快【点击购买】!

阿里云香港、新加坡VPS/1核/1G/25G SSD/1T流量/30M带宽/年付¥288【点击购买】

WordPress 通过自定义分类法获取自定义文章类型的相关文章

`微信`扫码 加好友

链接到文章: https://gkxyz.com/wordpress-tongguozidingyifenleifahuoquzidingyiwenzhangleixingdexiangguanwenzhang.html

推荐站点

评论已关闭