embedding shortcodes in php template

I think it needs to be like this: <?php $output=”[accordion]”; ?> <?php $args = array( ‘posts_per_page’ => ‘-1’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘category__in’ => $quicksand_categories ); $query = new WP_Query( $args ); foreach ($query->posts as $item) { $categories = wp_get_post_categories($item->ID); ?> <?php $output.='[accordion-item title=”‘.get_the_title($item->ID).'”]’.the_content().'[/accordion-item]’; ?> <?php } ?> <?php $output .= ‘[/accordion]’; ?> … Read more

Hacking ‘posts_per_page’ in WP_Query

Here’s some options: Keep The AJAX You drop out your posts_per_page => 15 query and keep the -1 query. Then after your map loop ( or before ) you can limit the amount of items showing using a counter: if( $map->have_posts() ) : $counter = 1; while( $map->have_posts() && $counter <= 15 ) : ?> … Read more

custom page with post content using read more

You’re actually doing this in a way that is far more complicated than necessary. The foreach is actually excessive. What you want to do is something more like this: $args = array( ‘posts_per_page’ => ‘-1’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘category__in’ => $quicksand_categories ); $query = new WP_Query( $args ); if ($query -> have_posts() … Read more

Sort results without WP_QUERY?

If you want to change the order of an already existing query, you shouldn’t create a new WP_Query object but instead use pre_get_posts to alter the existing query, which prevents multiple queries running unnecessarily. From the pre_get_posts docs: This hook is called after the query variable object is created, but before the actual query is … Read more

Get a list of ACF Repeater-Fields as array

Holy loop attack Batman! I think you can simplify this a lot: $the_posts = get_posts( array( ‘posts_per_page’ => ‘-1’, ‘post_type’ => ‘artists’, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘date’, ‘value’ => date( ‘Ymd’ ), ‘compare’ => ‘<‘, ), ) )); $the_list = array(); foreach ( $the_posts as $the_post ) { if ( … Read more