filter wp_query result with custom field values

If main_category is a category (custom taxonomy), then you’re querying it wrong. This should go like this: $electronics = array( ‘numberposts’ => -1, ‘post_type’ => ‘article’, ‘main_category’ => ‘electronics’ ); $query_electronics = new WP_Query( $electronics ); If that’s a custom field, use meta_query: $electronics = array( ‘numberposts’ => -1, ‘post_type’ => ‘article’, ‘meta_query’ => array( … Read more

Slashes stripped in ACF

Until this gets fixed, the only workaround I can see is to intercept the $_POST data and add extra slashes prior to ACF stripping them: /** * @link http://wordpress.stackexchange.com/q/143555/1685 */ function wpse_143555_acf_add_slashes() { if ( ! empty( $_POST[‘fields’] ) ) { foreach ( $_POST[‘fields’] as $k => $v ) { if ( ! is_array( $v … Read more

Can’t get “has_sub_field()” to work in a conditional [closed]

You need to use the has_sub_field() method inside an if() statement. I’ve only included the affected code below to highlight the specific changes required. if (has_sub_field(‘vimeo_id’)): // Added if() // … endif; You also need to a use the get_sub_field() function here as opposed to the has_sub_field() function: <iframe src=”https://player.vimeo.com/video/<?php echo get_sub_field(‘vimeo_id’); ?>”></iframe>

While loop with bootstrap [closed]

Try using the count variable to increment the loop. <div class=”panel-group” id=”accordion” role=”tablist” aria-multiselectable=”true”> <?php if(get_field(‘faq_general_ht’)): ?> <?php $count=0; ?> <?php while(has_sub_field(‘faq_general_ht’)): ?> <div class=”panel panel-default”> <div class=”panel-heading” role=”tab” id=”headingTwo”> <h4 class=”panel-title”> <?php echo ‘<a data-toggle=”collapse” data-parent=”#accordion” href=”#collapse’ .$count. ‘”aria-expanded=”true”>’ ?> <p><?php the_sub_field(‘faq_general_question_ht’) ?></p> </a> </h4> </div> <?php echo ‘<div id=”collapse’ .$count. ‘” class=”panel-collapse collapse” … Read more

Show only the future event (Advanced Custom Fields)

You need a meta query. There’s also documentation on ACF for querying dates. <?php $event = new WP_Query( array( ‘post_type’ => ‘gacr-event’, ‘posts_per_page’ => 5, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’, ‘meta_query’ => array( array( ‘key’ => ‘date’, ‘type’ => ‘NUMERIC’, // MySQL needs to treat date meta values as numbers ‘value’ => current_time( ‘Ymd’ … Read more