使用woocommerce产品标签

时间:2016-04-24 03:56:14

标签: php loops woocommerce

我正在从头开始构建一个woocommerce主题,我正在试图弄清楚如何使用产品标签显示自定义帖子类型。例如,我将苹果作为产品,并使用 apple 作为产品标签。

然后我有一个名为食谱的自定义帖子类型。我只想说我发布了一个名为 apple salad 的帖子,然后我也用 apple 这个词来标记它。

我想根据woocommerce产品标签显示自定义帖子类型(食谱)。如果在食谱自定义帖子类型下有任何带有单词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(); ?>

0 个答案:

没有答案