dop83362 2015-01-21 18:25
浏览 31

在Wordpress中向相关帖子添加高级自定义字段

I am trying to add a custom field value to related posts functionality, but am currently totally stuck at this:

<div class="relatedposts">  
<h3>Related posts</h3>  
<?php  
$orig_post = $post;  
global $post;  
$tags = wp_get_post_tags($post->ID);  

if ($tags) {  
$tag_ids = array();  
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;  
$args=array(  
'tag__in' => $tag_ids,  
'post__not_in' => array($post->ID),  
'posts_per_page'=>4, // Number of related posts to display.  
'caller_get_posts'=>1  
);  

$my_query = new wp_query( $args );  

while( $my_query->have_posts() ) {  
$my_query->the_post();

?>  

<div class="relatedthumb">  
<a rel="external" href="<? the_permalink()?>">
<?php 
$image = wp_get_attachment_image_src(get_field('image'), 'full');
print_r( $image[0] ); ?>
<?php the_title(); ?>
<img src="<?php echo $image[0]; ?>" />
</a>  
</div>  

<? }  
}  
$post = $orig_post;  
wp_reset_query();  
?>  
</div> 

This mostly works as it is code found online, it is just where to put the reference to the custom field that I seem to be missing. I am unable to place the variable and print_r of this anywhere to see the results.

  • 写回答

3条回答 默认 最新

  • duanfu9523 2015-01-22 05:22
    关注

    foreach($tags as $individual_tag) { $meta_values = get_post_meta($post->ID,'');

        if (in_array('VALUE SEARCHING FOR',$meta_values) {
            $tag_ids[] = $individual_tag->term_id;
        } // if
    } // foreach
    

    Fill in the appropriate blanks and this should filter your tags properly.

    HTH,

    =C=

    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?