Php 回显自定义页面';循环外的自定义字段
我有一个带有特定自定义字段的自定义页面模板。我想在循环外部显示这些自定义字段,但在同一页面内 这一个有效:Php 回显自定义页面';循环外的自定义字段,php,wordpress,custom-fields,Php,Wordpress,Custom Fields,我有一个带有特定自定义字段的自定义页面模板。我想在循环外部显示这些自定义字段,但在同一页面内 这一个有效: <?php echo get_post_meta( '244', 'custom_field_name', true ) ?> 但我希望动态工作,而不必输入页面的实际ID 如何调用回音中的页面ID?尝试以下操作: <?php global $wp_query; $postid = $wp_query->post->ID; e
<?php echo get_post_meta( '244', 'custom_field_name', true ) ?>
但我希望动态工作,而不必输入页面的实际ID
如何调用回音中的页面ID?尝试以下操作:
<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'Your-Custom-Field', true);
wp_reset_query();
?>
试试这个:
<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'Your-Custom-Field', true);
wp_reset_query();
?>
如果此调用在循环中,则用函数“获取id”替换id,此函数检索WordPress循环中当前项的id
<?php echo get_post_meta( get_the_ID(), 'custom_field_name', true ) ?>
见:
此外,您还可以通过全局变量
$post
访问post
$post = get_post();
<?php echo get_post_meta( $post->ID, 'custom_field_name', true ) ?>
$post=get_post();
请参阅:如果此调用在循环中,请将id替换为函数
获取id
,此函数检索WordPress循环中当前项的id
<?php echo get_post_meta( get_the_ID(), 'custom_field_name', true ) ?>
见:
此外,您还可以通过全局变量
$post
访问post
$post = get_post();
<?php echo get_post_meta( $post->ID, 'custom_field_name', true ) ?>
$post=get_post();
请参阅:就像一个符咒。谢谢工作起来很有魅力。谢谢