WP_Query a custom field value bringing back 0 results

UPDATE: Ok this should work, according to ACF’s documentation: $args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘page’, ‘meta_query’ => array( array( ‘key’ => ‘feature_on_front_page’, ‘value’ => ‘featured’, ‘compare’ => ‘LIKE’ ), ) ); Your code works for me. Can you see the feature_on_front_page custom field when you view the page(s) in the WordPress admin … Read more

Ordering posts by custom fields

This is a code I’m using ina website that I’m creating for a client. Maybe it can point you in the right direction: $current_date = date(‘Y-m-d’); $args = array( ‘post_type’ => ‘billboard_evento’, ‘posts_per_page’ => 4, ‘meta_key’ => ‘fecha-inicio’, //Declaring wich meta key I want to use ‘orderby’ => ‘fecha-inicio’, //Ordering the queried elements by meta … Read more

How to loop through a custom field for each post, & display?

You are missing “foreach” loop. Try this way $latest_cpt = get_posts(“post_type=event”); foreach ( $latest_cpt as $cpt_post ) { $theidone =$cpt_post->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 ; ;} echo $thisisworking; }

Generate slug and meta data if meta field is empty

Ok, after a little playtime, here is the answer: add_action(‘save_post’, ‘ocp_jobs_save_details’); function ocp_jobs_save_details(){ global $post; $genref = sanitize_title( dechex( time() ) ); if ( $post->post_type == ‘job’ ) { if ( $_POST[‘ocp_jobs_ref’] ) { $jobs_args = array( ‘ID’ => $post->ID, ‘post_name’ => strtolower( sanitize_title( $_POST[‘ocp_jobs_ref’] ) ) ); $myref = strtoupper( $_POST[‘ocp_jobs_ref’] ); } else{ … Read more

Custom fields and auto save

You need to check to see whether the $_POST data contains your custom field information before saving it: if (!empty($_POST[“intro”])) { update_post_meta($post->ID, “intro”, $_POST[“intro”]); } Also, WordPress will pass the post ID and post object into your callback if you ask it too. function save_intro($ID, $post){ //preserve the data in the admin section // … … Read more