Nested loop called with shortcode duplicating the content above the main loop

You have few errors in your code. Below you can see how it should look like: function cd_random_testimonial($atts) { // EXAMPLE USAGE: // [loop the_query=”showposts=1&post_type=testimonials&orderby=rand”] // Defaults extract(shortcode_atts(array( ‘the_query’ => ” ), $atts)); // de-funkify query $the_query = preg_replace(‘~&#x0*([0-9a-f]+);~ei’, ‘chr(hexdec(“\\1”))’, $the_query); $the_query = preg_replace(‘~&#0*([0-9]+);~e’, ‘chr(\\1)’, $the_query); // query is made $my_query = new WP_Query( $the_query … Read more

Inserting random posts

Combining two different custom post types in one single query, and still being able to control the number of each type of posts to be displayed can be a little tricky. If one single query is used with post_type = array( ‘type1’, ‘type2’…. ), you have to set posts_per_page to a considerably high number. Which … Read more

Loop to get current parent page “content” and his children content

Super basic example that gets the parents title and content and then the title and content for each child page. This is not just the loop, but an entire page template. <?php include_once( ‘header.php’ ); ?> <?php $my_wp_query = new WP_Query(); $all_wp_pages = $my_wp_query->query(array(‘post_type’ => ‘page’)); ?> <?php if ( have_posts() ) : while ( … Read more

Conditional Check in The Loop’s Parameters

I would change $args = array( ‘category_name’ => $category, ‘showposts’ => $numposts, ‘order’ => $order ); to $args = array( ‘showposts’ => $numposts, ‘order’ => $order ); if ( $category ) $args[‘category_name’] = $category; This way you never pass an empty category_name parameter as a query arg.

Custom Taxonomy + JQuery Tabs

This should work, but it’s not tested <div id=”tabs”> <ul id=”tab-menu”> <?php $terms = get_terms(‘category’); global $wpdb; $posts = array(); if ( is_array($terms) && ! empty($terms) ) { $active = null; foreach ( $terms as $i => $term ) { $ids = $wpdb->get_col( $wpdb->prepare(“SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d”, $term->term_taxonomy_id )); $articles_count = … Read more