Tag Info

New answers tagged

3

Welcome the the WordPress Stack Exchange and congrats on your first post! First off, you may not want to use query_posts() here. Second off - the_post() needs to be before the_title() as it sets up all the posts functions such as the_title(), the_permalink() etc. and queues the next post in your while loop. Your Loop should look like this: <?php ...


-1

Take the_post(); out of your loop. I've never seen that actually used in a theme.


-2

I thing, you should use this code for filter the check box category <?php // cat 42=Laos cat 57=2-4Days <?php $my_query_1 = new WP_query(array('category__and' => array(42,57))); ?> <?php while ($my_query_1->have_posts()) : $my_query_1->the_post(); ?> <a href="<?php the_permalink() ?>" rel="bookmark" ...


1

On the advise of Robert and Pieter I rewrote the loops using WP_Query instead of query_posts. It works now. Thanks guys. Here's the code: <ul class="tabs"> <li class="tab-link current" data-tab="tab-1">Most Popular</li> <li class="tab-link" data-tab="tab-2">Recent</li> ...


0

Here is a slight variation of an answer I have done on about the same scenario. What differs here is that you want less posts_per_page on page one STEP 1 Remove query_posts. You should never ever use query_posts Note: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the ...


-1

Try this code here <?php $paged = get_query_var('paged') ? get_query_var('paged') : 1; if($paged == 1){ $posts_per_page = 100; }else{ $posts_per_page = 300; } query_posts( array( 'posts_per_page' => $posts_per_page, 'post_type' => array( 'regularproducts', 'wpsc-product' ), 'paged' => $paged, )); ?>


1

In your functions.php you can create a function that will hook into the pre_get_posts hook. Something like (just an example): function alter_query($query){ $query->set('post_parent', 0); } add_action( 'pre_get_posts', 'alter_query' ); There you can alter the main query. That way while(have_posts()) : the_post(); will still just normally work. (You ...


1

It's not recommended to use query_posts(), check for example this warning note in the Codex: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new ...


0

Please use the following code: $arg = array ( 'posts_per_page' => get_option('posts_per_page'), 'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ) ); $wp_query = new WP_Query($arg); if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post(); // do something endwhile; ...


1

On the contrary to what is suggested by the accepted answer, you should never use query_posts Note: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new ...


1

Persuming "article_datetime" to be a numeric value, I would suggest that instead of using 'orderby' => 'meta_value' use 'orderby' => 'meta_value_num' If still query is slow, than remove: 'orderby' => 'meta_value', 'meta_key' => 'article_datetime', 'order' => 'DESC' and instead sort the result in php.


4

In addition to birgire's solution, as of WordPress 3.7, you can use Date parameters. Your arguments would look like this to filter posts from the last 7 days: $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC', // Using the date_query to filter posts from last week ...


0

The <!-- more --> tag isn't applied via the the_content filter, it's included in the get_the_content() function, which checks for the existence of the tag within the content using a regex and then outputs the more link appropriately. this output is filtered via the the_content_more_link filter, but since you're not using get_the_content() you won't be ...


-3

Set below code : <?php if (is_category()) { $posts = query_posts($query_string .'&orderby=title&order=asc'); } ?> You can exclude if condition if do not using category. For more reference: Alphabetizing Posts


1

You should use the pre_get_posts filter for this. For example, you could do this in your theme's functions.php file: function limit_category_posts( $query ) { if ( $query->is_archive() ) { // Do not do this for the date or category archives. if ( $query->is_date() || $query->is_category() ) return $query; ...


0

Your English isn't clear to me. What I understood is that you want to list archives of posts with specifications. Like, posts from the first week January, year 2013. Well, there is a dedicated function for this purpose and it's: wp_get_archives(); For example, if you want posts of the first week of January, year 2013: $args = array( 'type' => ...


0

Using query_posts is generally not recommended. Looking at the Codex, it specifically states: Note: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it ...



Top 50 recent answers are included