The variable that get_post_meta
was stored in was empty because I wasn’t getting an id
. I was trying to use this code on a category page, not a single event. Without an id
it couldn’t identify the post_meta
to use. So I corrected it with the following:
$latest_cpt = get_posts("post_type=event&numberposts=1");
$theidone =$latest_cpt[0]->ID;
$this_post_id = $theidone; //get_the_ID();
$key_2_value = get_post_meta( $this_post_id, 'custom_select', true );
if( ! empty( $key_2_value )) {
$thisisworking = $key_2_value ;