Articles of get post meta

If ACF meta_key has meta_value

I have an ACF field (options) that contains a list of options: Blue Red Green I would like to echo the option selected, ie: if(get_field(‘blue’) == true) { echo “You have selected the color Blue”; }

How to check if user meta field is empty in conditional else statement

Hello all I have a custom post type set up for my wordpress site within this custom post type i have a meta box with about 11 meta fields that I have added programatically. What I would like to do is check if one of the fields (which i have programmed to be a radio […]

get_post_meta as a list for drop down search filter

I was wondering if someone could help me out. I would like to create a dropdown search filter for my wordpress site. I would like the drop downs to be populated by meta_boxes values which i have for a custom post type. I know that <?php echo get_post_meta($post->ID, ‘meta_field’, true); ?> is the way to […]

get_post_meta not extracting title,permalink and posttype

i need to extract the post_type, title of the post and the permalink using get_post_meta i am trying following code for the same $title=get_post_meta($post_id,’title’,true); $permalink=get_post_meta($post_id,’the_permalink’,true); $posttype=get_post_meta($post_id,’post_type’,true); its doesn’t return anything. variables are always empty.

Display post meta conditionally based on it's value

I have a custom field that’s a radio button with 3 choices (yes, no, other). What I’d like to do is the following: [If custom field value is yes] Display something here [elseIf custom field value is no] Display something here [elseIf custom field value is other] [else] The code I have thus far isn’t […]

Add a custom class to the body tag using custom fields

There are certain posts where I want to manually append a custom body class to using custom fields. How do I go about it appending the class to the body tag when a certain custom field is added to a post? I have tried the following but the custom fields name tagbody is not shown […]

How to call a post's metadata in shortcode.php?

I’m not a terribly advanced WordPress developer, but I can kind of futz my way into a solution most of the time. This time, no such luck: I’m trying to write a shortcode to display a custom post type like a news feed on a page. This custom post type relies heavily on custom metadata […]

Meta box data is saved but NOT displayed in the meta box text field. Why?

I have a custom post type and I created it using the following code. /* DRAMAS */ register_post_type(‘dramas’, array( ‘label’ => ‘Dramas’, ‘show_ui’ => true, ‘supports’ => array(‘title’, ‘thumbnail’, ‘custom-fields’, ‘description’), ‘labels’ => array ( ‘name’ => ‘Dramas’, ‘singular_name’ => ‘Drama’, ‘menu_name’ => ‘Dramas’ ), ) ); Following code for the meta box mark up […]

Order a WP_Query by meta value where the value is an array

I have a WordPress custom query: $args = array( ‘posts_per_page’ => 2, ‘meta_key’ => ‘pworks_popular_posts’, ‘paged’ => $page_nr ); $query = new WP_Query($args); if($query->have_posts()) { while($query->have_posts()) { $query->the_post(); $pworks_post_meta = get_post_meta(get_the_ID(), ‘pworks_popular_posts’, true); $pworks_post_list[get_the_ID()] = $pworks_post_meta[‘Post visited’]; } } I am using this method to sort an array of post ids and post visits which […]

Get post_meta from specific post

I’m trying to get the post_meta from a specific post. However: the following code breaks my document: $img= get_post_meta(‘4996′,’ATHLETE-side_img’; Then further down in the code I was planning to use $img as an img source. Any help?