与标签相关的输出帖子

 mobiledu2502931473 发布于 2023-01-16 01:25

我使用的WordPress 3.9WooCommerce 2.1.8,并想知道我怎么可以显示用户当前正在查看四个相关帖子单行,这是相对于标签标签的帖子,而不是分类它在...

理想情况下,我想显示与我的单个产品页面底部当前正在查看的项目标签相关的四种产品,具体来说,每个相关帖子的特色图片或缩略图以及价格.如果可能,还可以从functions.php文件编写一个解决方案.

下面的代码是我到目前为止,它显示的是相关的帖子类别,而不是它所基于的标签:

    add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);

    function woocommerce_output_related_products() {
        $output = null;

        ob_start();

        woocommerce_related_products(array(
            'columns' => 4, 
            'posts_per_page' => 4,
            'post_type' => 'product',
            'fields' => 'ids',
            'meta_query' => $meta_query,
            'tax_query' => array(
               'relation' =>  'AND',
                 array(
                    'taxonomy' => 'product_cat',
                    'field' => 'id',
                    'terms' => $cats_array
                ), 
                array(
                    'taxonomy' => 'product_tag',
                    'field' => 'id',
                    'terms' => $tags_array
                )
            )
        )); 

        $content = ob_get_clean();
        if($content) { $output .= $content; }

        echo '
' . $output; }

任何帮助将不胜感激,
谢谢.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有