Pagination is not working on custom query inside a custom home page template

Use this for pagination <?php $paged = ( get_query_var( ‘paged’ ) ) ? absint( get_query_var( ‘paged’ ) ) : 1; $mostpopular_args=array( ‘post_type’ => ‘post’, ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘view_count’, ‘paged’ => $paged, ‘posts_per_page’ => ’10’, ); $wp_query = new WP_Query($mostpopular_args); while ($wp_query->have_posts()): $wp_query->the_post(); get_the_title(); endwhile; global $wp_query; $big = 999999999; // need an unlikely … Read more

“Where… like” query not working as expected

You should definitely be using prepare in this case, as your query is accepting input. It would be quite trivial for someone to compromise your database otherwise. Here we also use the new-in-4.0 esc_like method: $like=”%” . $mydb->esc_like( $facility_name ) . ‘%’; $results = $mydb->get_results( $mydb->prepare( “SELECT facility_name FROM facility WHERE facility_name LIKE %s LIMIT … Read more

Loads posts of different year via AJAX call

To Ajaxify the request you need two parts, a php function, hooked to the wp_admin_ajax ( and the wp_admin_ajax_nopriv if you want it to be available for non logged in user) and a JavaScript to request the AJAX. PHP add_action(‘wp_ajax_getpost_by_year’,’process_getpost_by_year’); add_action(‘wp_ajax_nopriv_getpost_by_year’,’process_getpost_by_year’); function process_getpost_by_year(){ $year = $_REQUEST[‘year’]; $args = array( ‘post_type’ => ‘post’, ‘ignore_sticky_posts’ => 1, … Read more

How to query custom post type one after another

Since version 4.0 is available ‘type’ option for ‘orderby’ argument in WP_Query. Also, thanks to the more powerful ORDER BY in WordPress 4.0 you can control how posts of a post type are ordered. Example (untested): $q = new WP_Query(array( ‘post_type’ => array(‘map’,’item’), ‘orderby’ => array( ‘type’ => ‘DESC’, ‘title’ => ‘ASC’ ) ));

Display the latest post from some selected authors

What you can do is the following: http://codex.wordpress.org/Function_Reference/get_posts_by_author_sql <?php $where = get_posts_by_author_sql( ‘post’, true, $user->ID); // get post query global $wpdb; $query = “SELECT ID FROM $wpdb->posts $where”; $post_ids = $wpdb->get_var( $wpdb->prepare( $query, ‘Get all posts’ ) ); ?> Did not try it but something simular in your case should help.

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