can’t get query to order posts by acf datepicker
You need to convert your saved format to the post_date format which is in Y-m-d H:i:s Only then will the comparators work properly with automatically generated query objects.
You need to convert your saved format to the post_date format which is in Y-m-d H:i:s Only then will the comparators work properly with automatically generated query objects.
Here’s a solution I’ve come up with, that works with WordPress 5.4 and ACF Pro 5.8.9. First you need this function somewhere in functions.php: /** * Get ID of the first ACF block on the page */ function sg_get_first_block_id() { $post = get_post(); if(has_blocks($post->post_content)) { $blocks = parse_blocks($post->post_content); $first_block_attrs = $blocks[0][‘attrs’]; if(array_key_exists(‘id’, $first_block_attrs)) { return … Read more
You need to define $landscape in the loop. You’re defining out so it is not part of your repeating portion. Move it down just under the while line so it looks like this: <?php $args = array( ‘post_type’ => ‘products’, ‘posts_per_page’ => 9 ); $the_query = new WP_Query( $args ); ?> <main class=”site-content”> <div class=”row”> … Read more
But how does the actual HTML get on the page? How does that SQL data translate into a page full of blocks? Normally the HTML for a block is inside the HTML comments. However, much like shortcodes, ACF blocks are rendered in PHP, so when the post is processed during the_content filter, that block is … Read more
<?php $total = 0; while(the_repeater_field(‘repeater’ )): the_sub_field(‘space_avail’ ); $total += intval( get_sub_field(‘space_avail’ ) ); endwhile; echo $total; ?> Notice the intval. It tells php to consider the result as an number, not as a string
Action acf/init is available for pro version only, and I think you forgot to mention that you’re using the free version because with pro version above code worked fine. For basic version you have to use acf/register_fields to register your custom fields. So you need to modify your code to: function af_barbershop_address_field() { if ( … Read more
As seen on ACF documentation, to check for a value before displaying it, simply use: <?php if( get_field(‘field_name’) ): ?> <p>My field value: <?php the_field(‘field_name’); ?></p> <?php endif; ?> So in your case, you are already getting the sub_field into $instruction, so simply use this: if( $instruction) ) :
I would try something like this: $lines = explode(“\n”, $instruction_textarea); // or use PHP PHP_EOL constant if ( !empty($lines) ) { echo ‘<ul>’; foreach ( $lines as $line ) { echo ‘<li>’. trim( $line ) .'</li>’; } echo ‘</ul>’; } It should work.
Dont use query_posts or WP_Query if you need it in the main loop. Dont ever use query_posts anyway. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php $current_id = get_the_ID(); ?> <?php echo $current_id ?> <h1><?php the_field(‘titleFart’, $current_id); ?></h1> <?php endwhile; // end of the loop. ?> <?php endif; ?> … Read more
Your action is triggered in wp_transition_post_status() which gets called by wp_insert_post() before the action save_post is triggered. save_post is the typical action to handle custom fields. ACF also works on this. Basically you have to wait until ACF is done with its stuff, means you’ll have to hook to save_post with a priority > 10 … Read more