i cleaned the code a lil bit
<?php
get_header();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'cat' => 3,
'posts_per_page' => 2,
);
global $wp_query;
$query = http_build_query( $args ) . "&paged=".$paged;
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query( $query );
if ($wp_query->have_posts()) :
$i = 1; $tags = array(); $post_ids = array();
while ( $wp_query->have_posts()) : $wp_query->the_post();
// $wp_query->next_post();
$post = get_post( get_the_ID() );
$tags = array_merge( $tags, wp_get_post_tags( get_the_ID(), array( 'fields' => 'names' ) ));
$post_ids[] = get_the_ID();
$post_url = get_permalink( get_the_ID() );
the_title();
the_excerpt();
endwhile;
if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
$wp_query = null; $wp_query = $temp;
endif; //have_posts
get_sidebar();
get_footer();
?>
Try it with this:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'cat' => 3,
'posts_per_page' => 2,
'paged' => $paged
);
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query( $args );
If this is not on a Page request (page template) there are even better ways to query:
http://www.billerickson.net/customize-the-wordpress-query/
http://developer.wordpress.com/2012/05/14/querying-posts-without-query_posts/
http://wordpress.stackexchange.com/questions/50761/when-to-use-wp-query-query-posts-and-pre-get-posts
🙁 it still doesnt work… i also tried that before…
im going crazy with this issue hehehehe
On what theme template file are you trying this?
it is a custom post type… it has its own archive template that i include in code
public static function include_news_template_function( $template_path ) {
$cat = get_the_category();
$cat = $cat[0]->name;
if ( get_post_type() == 'post' && $cat == 'NOTICIAS' ) {
if ( is_single() ) {
// checks if the file exists in the theme first,
// otherwise serve the file from the plugin
if ( $theme_file = locate_template( array( 'single-news.php' ) ) ) {
$template_path = $theme_file;
} else {
$template_path = plugin_dir_path( dirname(__FILE__ ) ) . 'theming/single-news.php';
}
}
if( is_archive() ){
if ( $theme_file = locate_template( array( 'archive-news.php' ) ) ) {
$template_path = $theme_file;
} else {
$template_path = plugin_dir_path( dirname(__FILE__ ) ) . 'theming/archive-news.php';
}
}
}
return $template_path;
}
and the filter is
add_filter( ‘template_include’, array(‘News’, ‘include_news_template_function’ ), 1 );
sorry, it isnt custom_post_type in this case its a regular post, with a known category
So if see this correct, when you view a normal post category archive and the category is ‘NOTICIAS’ use the post type archive template in your theme or use a post type archive template from your plugin instead of a normal category template.
Have you tried it without a query on the template (and a normal loop) with a query from your functions.php/plugin:
function my_post_queries( $query ) {
// not an admin page and is the main query
if (!is_admin() && $query->is_main_query()){
// use category slug for is_category()
if(is_category('noticias')){
$query->set('posts_per_page', 2);
}
}
}
add_action( 'pre_get_posts', 'my_post_queries' );
dude,
i think i am going to cry 😉 THAT WORKED!!
I just inserted that code in my main plugin’s file… i can keep my own archive template… (normal loop style, and so on…removing the query i had)
YOU ARE THE MAN, THANK YOU VERY MUCH… now lets see if it works everywhere i need it 😀
You’re welcome. I’m glad you’ve got it resolved 🙂