Custom Search Not Consistent with Results

I figured out the answer to my own question (finally!). I’m using the NineToFive template and I guess by default there’s a limit on the number of search results that’s returned (I’m not sure if that’s a WordPress default; maybe someone can clarify that). I changed my query to this: $s = new WP_Query(array(‘s’ => … Read more

Can I set my WP_Query to be a Main Query?

This is an overly complicated approach. pre_get_posts will work for any query and there are numerous ways to control when/how the callback behaves: Add and remove the callback: function dummy_action($q) { } add_action(‘pre_get_posts’,’dummy_action’); $q = new WP_Query( array( ‘post_type’ => ‘post’ ) ); remove_action(‘pre_get_posts’,’dummy_action’); Use a self-removing callback: function dummy_action($q) { remove_action(‘pre_get_posts’,’dummy_action’); } add_action(‘pre_get_posts’,’dummy_action’); $q … Read more

WP_Query create html structure

Use the built in current_post and post_count vars with php’s modulus operator to check where you are in the loop and output markup at the appropriate time. if( $grid_loop->have_posts() ): echo ‘<div class=”row”>’; while( $grid_loop->have_posts() ): $grid_loop->the_post(); ?> <div class=”col-xs-3 box”> <p><?php the_title(); ?></p> </div> <?php // if this is the third post // and … Read more

Add “Category” to Mysql Query

If I’m not missing something, the below should work for you. It is pretty much straight from the Codex: WP_Query – Custom Field Parameters. Do it like this: $args = array( ‘post_type’ => ‘post’, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘color’, ‘value’ => ‘red’, ‘compare’ => ‘=’ ), array( ‘key’ => ‘size’, … Read more

How to query the custom fields by language?

In qTranslate, there is this function that “dispatch” the language with the kind of string you have. Haven’t tested it yet, but you could do something like: $myString = get_post_meta( $post_id, ‘Functions’, true); echo qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($myMeta); This will display the right language on your post based on the current page’s language.

WP_Query order result by date AND meta_value

While WordPress does currently support multiple orderby it doesn’t actually support multiple order respectively. This was fixed very recently, see ticket #17065 (Independent ASC/DESC in multiple ORDER BY statement.) and will be available in 4.0 release with new array syntax: ‘orderby’ => array( ‘title’ => ‘DESC’, ‘menu_order’ => ‘ASC’ ).

Woocommerce query all products and categories

You can use wp_get_post_terms() $categories = wp_get_post_terms(get_the_ID(), ‘product_cat’, array(“fields” => “names”)); print_r($categories); The names of the product categories are returned as an array so you can either loop through them with a foreach or you can turn it into a string for example: $categories_list = implode(“,”, $categories); If you need more than just the names, … Read more