Filter my home page posts by category or by tag

You can use the following code to list the posts that are categorized under category id 3 OR have tag ‘urgent’ function exclude_category($query) { if ( $query->is_home ) { $query->set( ‘tax_query’, array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘ID’, ‘terms’ => 3 ), array( ‘taxonomy’ => ‘post_tag’, ‘field’ => ‘slug’, ‘terms’ => … Read more

tax_query operator woes

I’m not sure that there is a way to get it to use ‘OR’ instead of ‘AND’. Alternatively, you can do: $myquery[‘tax_query’] = array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘regions’, ‘terms’ => array(‘region1’), ‘field’ => ‘slug’, ‘operator’ => ‘IN’ ), array( ‘taxonomy’ => ‘population’, ‘terms’ => array(‘pop1’), ‘field’ => ‘slug’, ‘operator’ => ‘IN’ ), … Read more

Change or update WordPress loop based on dropdown selection

First use this code for populating parent dropdown. <select id=”parent”> <option>-</option> <?php if(taxonomy_exists(‘parent_taxonomy_name’)): $results = get_terms(‘parent_taxonomy_name’,array(‘fields’=>’all’,’parent’=>0)); if ($results): foreach ($results as $result): ?> <option value=”<?php echo $result->name; ?>”><?php echo $result->name; ?></option> <?php endforeach; endif; endif; ?> </select> You may need to use ajax/jquery to fill in the 2nd dropdown box. <select id=”child”> <option>-</option> </select> jquery … Read more

WordPress query_posts and orderby page order

I was going to suggest using &orderby=menu_order, but you already pointed it out in your comment. 🙂 p.s. you can answer your own question, I think. Since you found the answer to your question, just post your own answer. I think it”s kosher to accept your own answer?

WordPress pagination showing same posts on each page

You can replace the code with something like this <?php global $wp_query; $limit = get_option(‘posts_per_page’); $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; query_posts(array(‘posts_per_page’=>$limit,’paged’=>$paged,’category_name’=>’albertsons, carrs, dominicks, genuardis, heb, kroger, pavillions, publix, randalls,safeway,shop-rite,tom-thumb,vons,whole-foods’)); /* you may want to uncomment the below two lines if you are using custom page template*/ //$wp_query->is_archive = true; //$wp_query->is_home = false; then … Read more

Tricky WP Query

For that kind of complex query, I’d recommend running two queries and then merging the results. First, get an array for: get all posts WHERE ( post_type=”post” AND category = 7 ) Then, get an array for: ( post_type=”case-studies” AND meta_key = ‘homeslide’ AND meta_value = 1 ) Then use array_merge() to combine the arrays … Read more

Working with query_posts ( arrays and query strings)

I’d suggest not using $query_string to simplify things. If you’re using an array, stick with the array form for the query variables: global $wp; $paged = ((int)get_query_var(‘paged’)) ? (int)get_query_var(‘paged’) : 1; $s_array = array( ‘post_type’ => ‘blog’, ‘caller_get_posts’ => 1, ‘paged’ => $paged, ‘meta_query’ => array( array( ‘key’ => ‘votes_percent’, ‘value’ => ’50’, ‘compare’ => … Read more

how to exclude “featured” posts from the main loop?

This would be an appropriate use of query_posts(), with a post custom meta query. Since you’re querying by meta_key=featured_article&meta_value=on, you would then exclude on the same parameters. <?php // Setup the custom meta-query args $exclude_featured_args = array( ‘meta_query’ => array( array( ‘key’ => ‘featured_article’, ‘value’ => ‘on’, ‘compare’ => ‘!=’ ) ) ); // globalize … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)