Pagination for custom query on single.php

Well, for anyone else looking to solve a similar problem, I found this post, and it led me in the right direction: http://wordpress.org/support/topic/pagination-on-singlephp-causing-301-redirect?replies=9. I added this snippet of code to my functions.php, and I can paginate in custom queries without issue on single.php now. I don’t know enough about it to know what it does, … Read more

How to display images in related posts?

That is simple: <?php $categories = get_the_category($post->ID); if ($categories) { $category_ids = array(); foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id; $args=array( ‘category__in’ => $category_ids, ‘post__not_in’ => array($post->ID), ‘showposts’=> 5, // Number of related posts that will be shown. ‘caller_get_posts’=> 1 ); $my_query = new wp_query($args); if( $my_query->have_posts() ) { echo ‘<h3>Related Posts</h3>’; echo ‘<ul>’; while ($my_query->have_posts()) … Read more

creating wp query with posts with specific category

Use either: $the_query = new WP_Query(‘posts_per_page=2&category_name=events’); or $the_query = new WP_Query(array( ‘posts_per_page’ => 2, ‘category_name’ => ‘events’, // this is the category SLUG )); // EDIT Please note that category_name actually is the category slug (which is for one-word names originally the same). It is not the actual name (maybe having spaces, special characters etc. … Read more

meta_query on a date range using an array of values

I needed to get post with type event and the custom field “date” later than today, this sample of code worked perfectly for me, I hope it helps to someone in a similar situation. $today = date(“Y-m-d”); $today1 = date(“Ymd”, strtotime(“$today”)); $custom_meta = array( array( ‘key’ => ‘data_de_inicio’, ‘value’=>$today1, ‘compare’=>’>’, ‘type’=>’date’, ), ); $query = … Read more

How can i get the last post from wp multisite?

The orderby-parameter should be post_date instead of date. your code would look something like this: $blogs = get_last_updated(‘ ‘, 0, 1); foreach ($blogs AS $blog) { switch_to_blog($blog[“blog_id”]); $args = array( ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, ‘numberposts’ => 1, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘suppress_filters’ => true ); $lastposts = get_posts( $args ); foreach($lastposts … Read more

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