How to change the amount of posts previewed on a page?

You’re missing an s. $query->set(‘posts_per_page’, ‘1’); However – you probably don’t want to do this for every query, since that affects everything – widgets, back end, everything. You should make it conditional. For example: <?php function university_adjust_queries($query) { // If this is the main query, not in wp-admin, and this is the homepage if($query->is_main_query() && … Read more

Each post is showing twice in my custom query…?

There is really no reason to use raw sql to query posts. You can accomplish just about any type of query using the WordPress API. For full reference see the codex, Function Reference query posts. Try the following: global $post; $args=array( ‘post_type’ => ‘tutorial’, ‘orderby’ => ‘comment_count’, ‘posts_per_page’ => 10 ); $posts= query_posts($args); foreach ($posts … Read more

Multiple Category Query

Yes, it is. You’ll need a template page for the category (for example, category-30.php, where 30 is the id of the category you want to show with multiple subcategories). In the template, run through the standard loop for post from the original category if you want to, if not, the magic function will be wp_reset_query … Read more

Get Posts from Last 24 hours and Sort them via GD Star Rating

The posts_where filters the ‘WHERE’ part of the SQL statement, and not the query string. So $where .= “&post_date > ‘”.date(‘Y-m-d H:i:s’, strtotime(‘-24 hours’)).”‘”; should be $where .= ” AND post_date > ‘”.date(‘Y-m-d H:i:s’, strtotime(‘-24 hours’)).”‘”; Also as this hook is fired for every query (admin and public side), you should use some logic to … Read more

Display Content if Meta Checkbox is checked?

First make the custom post query with the WP_Query, and then we get the metadata by get_post_meta. Checkboxses are saved as boolean, that means either true or false. So make a check in the loop if checked or not (1=true, 0=false). <?php get_header(); ?> <?php // The Query $the_query = new WP_Query( array( ‘post_type’ => … Read more

All in One Calendar Plugin Custom Post Type Query [closed]

Ok so hope this helps someone. Unless you want to query the database directly, the trick is to include the following: $event = Ai1ec_Events_Helper::get_event($post->ID); thereafter you can retrieve the variables, for example: <?php query_posts(‘post_type=ai1ec_event’);?> <?php while ( have_posts() ) : the_post(); ?> <?php $event = Ai1ec_Events_Helper::get_event($post->ID); ?> <?php echo ‘<h5><a href=”‘.get_permalink().'”>’.get_the_title().'</a></h5>’; ?> <?php if( $event->multiday … Read more

Exclude some authors from query

Hey use this to grab all users excluding users with ID – 1,2,4 $blogusers = get_users(array(‘exclude’ => array(1,2,4))); Note – The function get_users_of_blog() is depricated, so it’d be good idea to use get_users() function which supports excludeing of users by their IDs.

wp_get_post_terms Order by not working

Your title is wp_get_post_terms Order by not working but if you use a custom post type you need to use wp_get_object_terms() I’m not sure what your aim is, but here is a code example you can try: $my_post_type=”post”; // edit this $my_taxonomy=”category”; // edit this $my_query = new WP_Query(array(‘post_type’ => $my_post_type,’posts_per_page’=>10)); if ($my_query->have_posts()) : while … Read more