Does query_posts have an effect on get_the_category?

The “main” query on the page is saved to a global called $wp_query. That global determines a great deal about the page, including both content and which template is used to display that content. Using $wp_query overwrites that main query and can cause some very basic things to fail but get_the_category() is probably not one … Read more

How can i show pagenavi in my author.php?

If you’re using the WP-PageNavi plugin, there are several FAQs on using it with a secondary query loop: http://wordpress.org/plugins/wp-pagenavi/faq/ this code is from one of the pages linked from that FAQ: $my_query = new WP_Query( array( ‘tag’ => ‘foo’, ‘paged’ => get_query_var(‘paged’) ) ); while ( $my_query->have_posts() ) : $my_query->the_post(); the_title(); // more stuff here … Read more

How to SQL query posts IDs by categories AND authors?

Not the best solution 😛 but this could help you: select distinct(p.ID) from wp_posts p, wp_term_relationships r, wp_term_taxonomy tt, wp_terms t WHERE p.post_author in (1, 2, 3) and r.object_id = p.ID and tt.term_taxonomy_id = r.term_taxonomy_id and tt.taxonomy = ‘category’ and tt.term_id = t.term_id and t.term_id in (1, 2, 3);

How to get specific string in explode array?

I see two problems here. One is that the explode() doesn’t actually specify the correct split string, which is ‘, ‘, WITH a space. What is written in the sample: ‘post_type’ => explode( ‘,’, $posttype ), What is written in the example shortcode: [myquery posttype=”cpt_press, cpt_two, cpt_three, cpt_etc”] Note that there is a comma AND … Read more

Writing less unnecessary code with WordPress

Try this function cat_loop ($key){ $fashion_cat = array( ‘category_name’ => $key, ‘posts_per_page’ => 4, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘post__not_in’ => $already_posted, ‘category__not_in’ => $private_categories ); // Add the loop. } cat_loop (‘fashion’); cat_loop (‘beauty’); cat_loop (‘lifestyle’); put the loop in function which has variable for the category_name … Read more

Category based on post id

WP_Query itself can’t do that logic internally but you can easily create the query dynamically. $args = array( ‘meta_key’ => ‘name’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’, ‘posts_per_page’ => ‘-1’ ); if ($post->ID == 1) { $args[‘category_name’] = ‘first’; } elseif ($post->ID == 2) { $args[‘category_name’] = ‘second’; } $custom_loop = new WP_Query($args);