Echo array value

If you just need to have the print_array($var) provide an array of values, then you need to change the database function from $wpdb->get_results to $wpdb->get_var. You are retrieving just one value from the database, so get_var is the function which will return that specific value directly. Edit: You can create a comma separated list from … Read more

Custom taxonomy query showing more than 4 posts

This is why code indentation is so important! Your posts_per_page argument is actually part of your tax_query: ‘post_type’ => ‘regularproducts’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘products-category’, ‘field’ => ‘slug’, ‘terms’ => $course_terms, //the taxonomy terms I’d like to dynamically query ‘posts_per_page’ => ‘4’ ), ), ‘orderby’ => ‘title’, Instead, you should have: $wp_query = … Read more

How do I get all results from my query

You can use posts_per_page to return all post from the database Just little modification in your WP query <?php $query = new WP_Query(array(‘post_type’ => ‘any’,’posts_per_page’=>-1)); ?> Try with this modification if it works for you.

mySQL queries are executed twice on wordpress website

The use of wpdb->insert and wp_insert_post both accomplish an SQL Insert, which is why you’re seeing 2 records each time. You must use only one instance of an insert method, and then Pass $my_post to WP_Query CLARIFICATION As Milo points out in his comment wpdb->insert will insert into any table, while wp_insert_post is used to … Read more