Pagination not working with custom loop

I’ve run into this problem with PageNavi before. My solution is to hijack the $wp_query variable temporarily and then reassign it after closing the loop. An exmaple: <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args=array( ‘post_type’=>’post’, ‘cat’ => 6, ‘posts_per_page’ => 5, ‘paged’=>$paged ); $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query($args); /* … Read more

Filter posts by author selected in page

You can write your own query to include or exclude posts from an Author, This page has documentation about the options you can pass to a query. http://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters Here is an example to only get posts from the user $author. $author_query = new WP_Query(‘author_name=”.$author); for user “Amin’ : 🙂 $author_query = new WP_Query(‘author_name=Amin’);

Search a meta field for a value in all posts

WP_Query will return a WP_Query object. An object will never match the string $ip that you are comparing it to. What you need to be doing is checking whether results were returned, which you can do by checking the found_posts property: $ip = $_SERVER[‘REMOTE_ADDR’]; $query = new WP_Query( array( ‘ignore_sticky_posts’ => true, ‘meta_key’ => ‘voted_IP’, … Read more

How to store post rating system data post independent?

What you want is actually pretty easy to achieve. The code from the tutorial you used saves and gets the data post dependent via update_post_meta() and get_post_meta(), which doesn’t suit your use case. You just have to store your data post independent. This thought relates to the array of IP keys and time values you … Read more

Category slug in in loop always the same?

First, Please don’t use query_posts.. Second, you’ve set $category somewhere in code not posted and never change it. How do you expect it to be different? What you need to do is retrieve the categories, which isn’t that hard… $cq = new WP_Query(‘category__in=4′); while ( $cq->have_posts() ) { $cq->the_post(); $c = wp_get_object_terms($post->ID,’category’); var_dump($c); // echo … Read more

How to fix pagination for custom loops?

The Problem By default, in any given context, WordPress uses the main query to determine pagination. The main query object is stored in the $wp_query global, which is also used to output the main query loop: if ( have_posts() ) : while ( have_posts() ) : the_post(); When you use a custom query, you create … Read more

Retrieve posts in custom post type and specific taxonomies

Both get_posts() and wp_query() should be able to do this by passing the tax_query array into them. Example: $query = array( ‘post_type’ => ‘portfolio’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘clients’, ‘field’ => ‘slug’, ‘terms’ => array( ‘acme’ ) ) ), ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’ ); $posts … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)