Query multiple custom post types in single loop

Just change the post_type bit to: ‘post_type’ => array(‘testimonial’, ‘other_post_type’, ‘another-post-type’), Assuming that taxonomy is valid across all 3 post types. Otherwise you’ll have to leave that out. Why? You can pass an array to post_type field.

Display all posts in a custom post type, grouped by a custom taxonomy

So, you might consider automating the multiple queries. First, get the list of terms in your custom taxonomy, using get_terms(): <?php $member_group_terms = get_terms( ‘member_group’ ); ?> Then, loop through each one, running a new query each time: <?php foreach ( $member_group_terms as $member_group_term ) { $member_group_query = new WP_Query( array( ‘post_type’ => ‘member’, ‘tax_query’ … Read more

Should we trust the post globals?

There is a sad truth: you can never ever be sure that some code will not break your code, and there is nothing you can do to prevent that. Especially in WordPress, where everything is global. That said, yes, global $post is one of the most used global var, so using special care for it … Read more

Print Current Post Index number within Loop

Actually I want to assign ID’s as per post index ! Here’s your code that I modified. <?php global $wp_query; $posts = $woo_options[‘woo_latest_entries’]; query_posts(‘post_type=post&category_name=company’); if ( have_posts() ) : while ( have_posts() ) : the_post(); $count++; $index = $wp_query->current_post + 1; ?> <div id=”my_post_<?php echo $index; ?>”> <!– Post Content Goes Here –> </div> <?php … Read more

Split Content and Gallery

Open to anybody who can simplify this but here’s what I came up with that worked for me. First thing’s first – get the gallery, using get_post_gallery(), as soon as the loop starts: <?php if( have_posts() ) : ?> <?php while( have_posts() ) : the_post(); $gallery = get_post_gallery(); $content = strip_shortcode_gallery( get_the_content() ); ?> <div … Read more

Display featured products through custom loop in woocommerce on template page

Change your args to be like this: $meta_query = WC()->query->get_meta_query(); $meta_query[] = array( ‘key’ => ‘_featured’, ‘value’ => ‘yes’ ); $args = array( ‘post_type’ => ‘product’, ‘stock’ => 1, ‘showposts’ => 6, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘meta_query’ => $meta_query ); If you go to wp-content/plugins/woocommerce/includes/class-wc-shortcodes.php (@595) you can find how it’s done for … Read more

Can i merge 2 new WP_Query($variable) ‘s?

You won’t do much good just merging the arguments, you need to merge the resulting posts array and the post_count count. This works for me: //setup your queries as you already do $query1 = new WP_Query($args_for_query1); $query2 = new WP_Query($args_for_query2); //create new empty query and populate it with the other two $wp_query = new WP_Query(); … Read more

Resetting post data to previous loop in nested loops

I’m going to answer this myself, but it was the very clever @simonwheatley of Code for the People that solved this one for me. Instead of using wp_reset_postdata() or wp_reset_query(), you can use the following: $publication->reset_postdata(); Where $publication is your query object. The working code now looks like: $publication = new WP_Query( array( ‘connected_type’ => … Read more

Why should I put if(have_posts()), is while(have_posts()) not enough?

The WordPress template loader will include the appropriate contextual template file in many circumstances, even if the query for that context returns no posts. For example: The Main Blog Posts Index Category Archive Index (Category exists, but has no posts) Tag Archive Index (Tag exists, but has no posts) Author Archive Index (Author exists, but … Read more

deneme bonusu veren sitelerbahis casinomakrobetceltabetpinbahispolobetpolobet girişpinbahis girişmakrobet girişpulibet girişmobilbahis girişkolaybet giriş