Problem in exploding the_content to array

You have a couple of issues here the_content() echos the content to screen. You should be using get_the_content() which returns the content. Just remember, get_the_content() is unfiltered, so if you need filtered content, use apply_filters( ‘the_content’, get_the_content() ) which will return filtered content. Your explode() function is probably wrong as well. You are using a … Read more

How to add div blocks after certain set of post

use % to set the template(style) or you can use :nth-child(16n+1) … <?php if (have_posts()) : ?> <?php $count = 0; ?> <?php $st = 16; //after how many blocks you want to repeat the pattern <?php while (have_posts()) : the_post(); ?> <?php $count++; ?> <?php if ($count%$st == 1) : ?> <div class=”style-1″><?php the_content(); … Read more

empty query breaks other queries

Before we start, you should properly indent your code and remove php spam. This makes your code much easier to read and understand. Secondly, rather use curlies ({}) instead of syntax like :, endif and endwhile. It is easier to debug and to read. Just another tip, comment your code for future reference, it makes … Read more

Query Custom Post Types with checkboxes

You aren’t constructing the meta_query correctly. It is close but not quite right. $searchArray = array(); $searchArray = array(‘relation’ => ‘OR’,); // here is the change // loop over checked checkboxes if(!empty($_POST[‘course_location’])) { foreach($_POST[‘course_location’] as $check) { // echo ‘<h1>’.$check.'</h1>’; $searchArray[] = array(‘key’ => ‘course_location’,’value’ => $check,’compare’ => ‘LIKE’,); } } As you have it … Read more

Insert widgets into loop/custom query at every nth position

If you can get an index of your post then utilize % for CTA breaks. <?php // Your CTA Content $cta_array = array( “Some different content 1”, “Some different content ABC”, “Some different content XYZ”, ); $cta_inx = 0; // index $cta_len = count($cta_array); // max $cta_interval = 5; // breaks every x posts // … Read more

Custom Query – Based on user input

While this is primarily a SQL question, there are WordPress components and Core has no efficient mechanism to pull this data that I am aware of. This has long been a problem in Core in my opinion. So: global $wpdb; // group name key $meta_key = ‘_create_new_group’; if (!empty($_REQUEST[‘q’])) { // user input $search = … Read more

Post with certain term and without any term

This should be possible with the tax_query parameters for WP_Query. The query is either for posts where any term NOT EXISTS, OR, for any posts where the term IDs are IN the provided array. ‘tax_query’ => array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘group’, ‘operator’ => ‘NOT EXISTS’, ), array( ‘taxonomy’ => ‘group’, ‘field’ => … Read more