Why isn't get_post_meta working?

后端 未结 9 1055
予麋鹿
予麋鹿 2020-12-12 05:12

Simple Wordpress problem - get_post_meta is not retrieving custom field values. Here\'s the code that is pulling from the custom fields:



        
相关标签:
9条回答
  • 2020-12-12 06:04
    <?php get_post_meta(get_the_id(), 'YOURKEY', true) instead of get_post_meta($post->ID, 'YOURKEY', true) ?>
    

    Works for me!

    0 讨论(0)
  • 2020-12-12 06:13

    Its because of auto save. use these lines for preventing auto save and user privileges.

    // Bail if we're doing an auto save  
    if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; 
    
     // if our current user can't edit this post, bail  
    if( !current_user_can( 'edit_post' ) ) return;
    
    0 讨论(0)
  • 2020-12-12 06:13

    You could also use get_post_meta( $loop->post->ID, 'yourkey', true ); if you are using $loop = new WP_Query( $args ); or something similar.

    0 讨论(0)
提交回复
热议问题