Why is my WP Query not returning first result’s post meta?

$show_date = get_field(‘show_date’); $show_venue = get_field(‘show_venue’); // print ‘<pre>’; // print_r($show_date); // print ‘</pre>’; $query->the_post(); You are setting the active post AFTER getting the values. Put $query->the_post() always at the top of that while loop, so that the other functions can rely on the global $post variable being set correctly.

Is there a better way of retrieving the name of an acf pagelink type from current post?

The page link field actually stores the post ID, which gets formatted internally by the get_field function on output. The 3rd argument for get_field lets you disable that output formatting so you just get the ID back, which you can then use to get title and permalink for that post: $post_id = get_field( ‘bookitall_roomstype’, false, … Read more

html element to separate php variable strings – ACF datepicker

thanks to @kero, i managed to do something like this : <?php $dayNumber = “l”; $weekDay = “j”; $month = “F”; $year = “Y”; $unixtimestamp = strtotime(get_field(‘date’)); ?> <?php echo ‘<span>’ . date_i18n($dayNumber, $unixtimestamp) . ‘</span>’; ?> <?php echo ‘<span>’ . date_i18n($weekDay, $unixtimestamp) . ‘</span>’; ?> <?php echo ‘<span>’ . date_i18n($month, $unixtimestamp) . ‘</span>’; ?> … Read more

ACF not showing

the_field() function shows the value and it doesn’t get/return anything. Like the_title() and other template tags starting with the_. It means that: This line prints the value and $hero variable is empty. $hero = the_field(‘hero_title’); This line prints only <h1> tags. echo ‘<h1>’.$hero.'</h1>’; What you want is: echo ‘<h1>’ . get_field(‘hero_title’) . ‘</h1>’;

Image Shortcode from ACF ID

It’s because you have forgot to use $atts[‘post_id’] please find below code. function acf_featured_item_shortcode( $atts ) { // Attributes $atts = shortcode_atts( array( ‘post_id’ => ”, ), $atts ); $post_id = $atts[‘post_id’]; $image = get_field(‘featured_item’, $post_id ); $size=”medium”; // (thumbnail, medium, large, full or custom size) if( $image ) { $output = wp_get_attachment_image( $image, $size, … Read more

Is there a better way to pull in custom content without querying posts?

It’s not a hack, this is what databases are designed for- querying large quantities of data. If you’re concerned about load, you should employ caching on data that doesn’t change frequently. That said, you should not be using query_posts to create additional queries. Really, you shouldn’t be using query_posts at all. Create additional queries via … Read more

ACF Add fields values to newly inserted post [closed]

You can do this instead of using update_field(): update_post_meta($post_id, ‘fieldname’, $value); update_post_meta($post_id, ‘_fieldname’, ‘field_’ . uniqid()); // `uniqid() is a native PHP function. This is also how ACF creates the field keys Also, depending where you are retrieving the value, you may also have to pass the post id. the_field(‘fieldname’, $post_id);