最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Inserting post content into pages when using custom taxonomies

programmeradmin0浏览0评论

I am inserting a snippet of text into posts when posts have a certain taxonomy.

I want this text to be editable by WP users n the admin area.

The following doesn't seem to want to do anything for me, admittedly I copied pasted and amended from another thread on here.

<?php
if ( has_term( 'ART', 'product_relevance' ) ) {
?>
<div class="row">
           <div class="notification col-lg-9 order-1">
<?php
    $my_id = 927;
    $post_id_927 = get_post($my_id, ARRAY_A);
    $title = $post_id_927['post_content'];
?>

           </div>
</div>
 <?php
}
?>

The if statement works fine, it is just the block calling the post by ID.

I am inserting a snippet of text into posts when posts have a certain taxonomy.

I want this text to be editable by WP users n the admin area.

The following doesn't seem to want to do anything for me, admittedly I copied pasted and amended from another thread on here.

<?php
if ( has_term( 'ART', 'product_relevance' ) ) {
?>
<div class="row">
           <div class="notification col-lg-9 order-1">
<?php
    $my_id = 927;
    $post_id_927 = get_post($my_id, ARRAY_A);
    $title = $post_id_927['post_content'];
?>

           </div>
</div>
 <?php
}
?>

The if statement works fine, it is just the block calling the post by ID.

Share Improve this question asked May 1, 2019 at 16:22 R ReveleyR Reveley 1617 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

That code never outputs anything to the page:

<?php if(has_term('ART', 'product_relevance')):
   $my_post = get_post(927);
   if(isset($my_post->post_content)): ?>
      <div class="row">
         <div class="notification col-lg-9 order-1">
            <?php echo $my_post->post_content; ?>
         </div>
      </div>
   <?php endif; ?>
<?php endif; ?>

Untested, but in essence you need to do something with the post content.

发布评论

评论列表(0)

  1. 暂无评论