Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用woocommerce产品标签将自定义帖子类型显示为相关帖子_Php_Loops_Woocommerce - Fatal编程技术网

Php 使用woocommerce产品标签将自定义帖子类型显示为相关帖子

Php 使用woocommerce产品标签将自定义帖子类型显示为相关帖子,php,loops,woocommerce,Php,Loops,Woocommerce,我正在从头开始构建一个woocommerce主题,并试图找出如何使用产品标签显示自定义帖子类型。例如,我把苹果作为一种产品,我用苹果这个词作为产品标签 然后我有一个自定义的帖子类型,名为recipes。比方说,我发表了一篇名为《苹果沙拉》的帖子,然后我还用“苹果”这个词给它贴上了标签 我想根据woocommerce产品标签显示自定义帖子类型(recipes)。如果在recipes custom post type下有任何带有apple字样的产品标签,则会显示出来。我有这段代码,正在进行中,并且仍

我正在从头开始构建一个woocommerce主题,并试图找出如何使用产品标签显示自定义帖子类型。例如,我把苹果作为一种产品,我用苹果这个词作为产品标签

然后我有一个自定义的帖子类型,名为recipes。比方说,我发表了一篇名为《苹果沙拉》的帖子,然后我还用“苹果”这个词给它贴上了标签

我想根据woocommerce产品标签显示自定义帖子类型(recipes)。如果在recipes custom post type下有任何带有apple字样的产品标签,则会显示出来。我有这段代码,正在进行中,并且仍在试图找出要更改的部分。我对PHP不是很流利,我一直在研究任何类似于我的问题的帖子

<?php //Related Post by Tag
    $tags = wp_get_post_tags($post->ID);

                  if ( $tags ) {
                  $first_tag = $tags[0]->term_id;

                          $args = array(
                                'tag__in' => array( $first_tag ),
                                'post_type' => 'recipes',
                          );

                          }

                  $related_post = new WP_Query( $args );
                  if( $related_post->have_posts() ) : while ( $related_post->have_posts() ) : $related_post->the_post();

                            ?>

                  <div class="full-width related-post">
                      <span>Recommended</span>
                      <h2><?php the_title(); ?></h2>
                  </div>

    <?php wp_reset_postdata(); ?>

    <?php endwhile; else: ?>


    <?php endif; ?>

<?php wp_reset_query(); ?>

推荐