【问题标题】:Trying to get the custom Post type category link in Wordpress for the current post as meta data of the post尝试在 Wordpress 中获取当前帖子的自定义帖子类型类别链接作为帖子的元数据
【发布时间】:2021-03-09 02:56:24
【问题描述】:

我正在尝试在 WordPress 的自定义帖子类型中放置指向视频艺术家的链接。一切正常,但 term_id 没有迭代。

<?php
$args = array(
    'post_type'      => 'video',
    'posts_per_page' => 4,
    'taxonomy' => $term->name,
    'number' => $term->term_id,
);
        
$q = new WP_Query( $args);

if ( $q->have_posts() ) {
    while ( $q->have_posts() ) {
    $q->the_post();        
        //Your template tags and markup like:
        ?>
        
      <div class="card">
          <div class="bg-img"><img  alt="Norway" style="width:100%" src="<?php the_post_thumbnail( 'thumbnail' );?></div>
          <div class="content">
            <h4 style="color: green;"><?php the_title( ); ?></h4>
             <h5 class="artist-name"><?php
  
  $terms = get_terms( $args );
    foreach( $terms as $term ){
  
        echo '<div style="color: black;"><a href="' . esc_url( get_term_link( $term->slug, 'band' ) ) . '">' . esc_html( $term->name ) . " ". $term->term_id . '</a></div>'; 
            
    }  ?>

【问题讨论】:

    标签: php wordpress wordpress-theming


    【解决方案1】:

    根据您的代码,您似乎使用了“get_terms”的帖子参数,这是不正确的,这就是您没有获得正确术语数据的原因。

    您可以查看术语over here的查询参数来了解。

    【讨论】:

    • 如果这个答案对你有帮助,请接受并投票。谢谢!
    猜你喜欢
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-27
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 2015-10-11
    • 1970-01-01
    相关资源
    最近更新 更多