dongyun3805 2012-02-16 21:17 采纳率: 0%
浏览 24

wordpress从帖子访问自定义字段

I have looked everywhere and am not finding the answer I'm looking for.

Basically I want to access information from a post and display it on my front page.

I'm using a plugin called Advanced Custom Fields to organize my content for each post.

I can retrieve the post title like this.

$post_id = 148;
$queried_post = get_post($post_id);
?>
<h2><?php echo $queried_post->post_title; ?></h2>
<?php echo $queried_post->field_4f2af94aa1371; ?>

But I can not access the value of the custom fields. Can anyone help me?

  • 写回答

1条回答 默认 最新

  • doushan6692 2012-02-16 21:23
    关注

    Use the get_post_meta function

    <?php echo get_post_meta($post_id, 'CUSTOM_FIELD_NAME', TRUE ); ?>
    
    • first param: post ID
    • second param: key (name of the meta value)
    • third param: true if you want a single value (instead of array)

    For more information; http://codex.wordpress.org/Function_Reference/get_post_meta

    评论

报告相同问题?

悬赏问题

  • ¥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()实现黑框里写入与删除?