Pre-existing arguments when using queries
When should you use WP_Query vs query_posts() vs get_posts()?
When should you use WP_Query vs query_posts() vs get_posts()?
you don’t need if/else on the counter, just check if $count == 3 or 5 to inject a sticky post, insert a regular post in every iteration of the loop, and increment the counter at the bottom.
Read through this and this.
Check that index.php is indeed being used, it’s last resort kind of template when there is no more suitable one. If you need this in multiple places across the site it might be better to run this in some hook, rather than in template file.
Have a look at the category parameters of WP_Query
you really shouldn’t use query_posts() for anything other then the main query of the page. Instead you should use wp_query() or get_posts() , also since you return a value before running wp_reset_query() then its never actually being reset. so change your shortcode to this: function casestudy_shortcode($atts){ extract(shortcode_atts(array( ‘type’ => ‘case_studies’, ‘limit’ => ‘1’, ‘case’ => … Read more
Here’s one way of doing it: <?php $courses = get_posts( array( ‘post_type’ => ‘courses’, ‘posts_per_page’ => -1 ) ); if ( $courses ) { print “\n” . ‘<div style=”background:pink”>’; foreach ( $courses as $course_count => $post ) { setup_postdata( $post ); the_title( “\n”, ‘<br>’ ); if ( 5 == $course_count ) { print “\n” . … Read more
Think I’ve figured it out. Here’s the code I used courtesy of this thread on the WP Support Forum. Just replace ()<?php the_author_posts_link(); ?>() with whatever excerpt code you want to use. And Voila! <?php //list 5 latest authors $authors = array(); $count = 0; $args=array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, … Read more
If you have the category ID you can use the category__in parameter eg: <?php $custom_posts->query(array(‘category__in’ =>array(1,2,3))); ?>
Code you are after: <?php $wp_user_search = new WP_User_Query( array( ‘role’ => ‘administrator’ ) ); $admins = $wp_user_search->get_results(); $admin_ids = array(); foreach($admins as $admin) { $admin_ids[] = $admin->ID; } $args = implode(‘,’, $admin_ids); query_posts(“author=$args”); ?>