Exclude an array

Strange but it works with same principle I was trying to. Maybe I had some grammer error. Here is a code if somebody will need it in future as there was nothing in search result: // get product media library $mediaArgs = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘numberposts’ => -1, ‘post_status’ => null, … Read more

How to query post like normal search would do. within search.php page

This is what i did: I run another query without pagination like this: $newQuaryVars=”&posts_per_page=99999999999999&post_type=post”; $posts = query_posts($query_string .$newQuaryVars); $categoriesList = array(); $categoriesAmounts = array(); Then in the while have posts i did the following: while ( have_posts() ) : the_post(); $postCategories = get_the_category(); if($postCategories){ foreach($postCategories as $categoryInfo) { $categoriesAmounts[$categoryInfo->term_id][‘amount’]++; $categoriesList[$categoryInfo->term_id] = array( ‘name’ => $categoryInfo->name, … Read more

Mysql query and order meta value

While the WPDB class, or its global $wpdb instance are your friend when it comes to querying custom tables or WP core data that does not have a higher-level API, it is overkill to use it to query posts. Instead, read up on WP_Query. In your case, you’d use it like so: $args = array( … Read more

If Query In Sidebar

Assign the return value of the first check to a variable, and test if there is something in it: if ( $quote = get_post_meta( get_the_ID(), ‘FeaturedQuote’, TRUE ) ) { ?><h3 class=”featuredquote”><?php the_title(); ?></h3> <blockquote><span class=”bqstart”>&#8220;</span><?php echo $quote; ?> <span class=”bqend”>&#8221;</span></blockquote> <?php } elseif ( $img = get_post_meta( get_the_ID(), ‘InsertFullImg’, TRUE ) ) { echo … Read more

Optional Meta Query

All of the real work here is being done by $geoDataStore->getPostIDsOfInRange. That is where the search is done and that is what isn’t returning the results you want. WP_Query just pulls the specified post IDs. There is no reason you should have to abandon that part of the code, though you may want to add … Read more

is_tax() function not working as expected

If you take a look at this part of the WP_Query class: switch ( $tax_query[‘taxonomy’] ) { case ‘category’: $this->is_category = true; break; case ‘post_tag’: $this->is_tag = true; break; default: $this->is_tax = true; } then it looks like on category archive pages where is_category gives true then is_tax is false. So it looks like you … Read more

Pagination on with query_posts in custom post type template

@Milo Thanks, the pre_get-posts seems to work perfectly. I was missing that before, thought my choices were between wp_query and query_posts. The below should ONLY alter the query on the “rg_blog” custom post type archive, right? function blog_filter($query) { if ( !is_admin() && $query->is_main_query() ) { if ($query->is_post_type_archive(‘rg_blog’)) { $query->set(‘post_type’, ‘post’); } } } add_action(‘pre_get_posts’,’blog_filter’);

Auto Populate Custom Field with Complex Value That Increase by One?

I suppose you need somewhere to globally store last order number. Preferable in table wp_options. Method update_option will help you. Then you need to make a function which will fires everytime when new order appears. something like that: add_action( ‘save_post’, ‘setOrderNumber’); function setOrderNumber($post_id) { $slug = ‘orders’; // slug of your post_type called “Orders” if … Read more