How to create a multidimensional array with multiple loops

I don’t think this is a restrict WordPress question, but you might try $args = array( ‘posts_per_page’ => ‘-1’, ‘post_type’ => ‘work’, ‘orderby’ => ‘ID’, ‘order’ => ‘DESC’, ); $data = array(‘work’ => array()); $loop = new WP_Query($args); if( $loop->have_posts() ): while( $loop->have_posts() ): $loop->the_post(); $id = $loop->post->ID; $attachments=array(); if(get_field(‘work’)): while(has_sub_field(‘work’)): $attachment_id = get_sub_field(‘image’); $caption … Read more

Post loop count is not in order

a) Try to initialize the $count variable before your loop: $counts=0; $loop = new WP_Query( array( ‘post_type’ => ‘focus-areas’, ‘posts_per_page’ => -1 ) ); while ( $loop->have_posts() ) : $loop->the_post(); $counts++; echo $counts; echo ” – “; endwhile; b) or use the current_post method (starts at 0) of WP_Query: $loop = new WP_Query( array( ‘post_type’ … Read more

If/Else Statement for Advanced Custom Fields

<?php if( get_field(‘parent_repeater’) ) : while( has_sub_field(‘parent_repeater’) ) : $some_bool = get_sub_field(‘true’); $sf1 = get_sub_field(‘sub_field_1’); $sf2 = get_sub_field(‘sub_field_2’); if( $some_bool == true ){ echo $sf1 . $sf2; } else { echo $sf1; } endwhile; endif; ?> You must use the non-echoing version of the function. Use the get version. Also, I advise you to use … Read more

Basic do shortcodes question

the_field() is an ACF function and will echo content. It follows the WordPress (somewhat) pattern whereby functions with the_ at the front will echo content and functions beginning with get_ return content. Displays the value of the specified field. (this is the same as “echo get_field($field_name)”) http://www.advancedcustomfields.com/resources/functions/the_field/ Using the wrong function, as you have, will … Read more