Is there a conditional tag for latest post or do i need a query?

Within an ordinary WordPress Loop, the following would identify the first post in the Loop, which would be the latest if posts are ordered by date descending. global $wp_query; // might not be necessary; depends on context if (is_paged() && 0 === $wp_query->current_post) { echo ‘first-post’; } I don’t know how your custom function works … Read more

Sorting posts according to view counts not working

Your code doesn’t make sense. You use query_posts(), which you should never do, but all that does is clobber the main query. You don’t use the clobbered query though. You then use get_posts() with an undefined (so far as code posted indicates) argument list, so it is not going to return what you expect. I … Read more

How to display all posts with today’s same month and day only?

You can achieve this with the date_query parameters added in version 3.7. To modify the main query on your posts page before it is run and apply the date_query parameters, we use the pre_get_posts action: function historical_posts_list( $query ){ if( $query->is_home() && $query->is_main_query() ){ $date_query = array( array( ‘month’ => date( ‘n’, current_time( ‘timestamp’ ) … Read more

posts_per_page doesnt work

Yeah, use ‘nopaging’ => true http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters $Poz = array( ‘posts_per_page’ => 3, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘update_post_term_cache’ => false, ‘update_post_meta_cache’ => false, ‘nopaging’ => true, ); $the_query = new WP_Query( $Poz );

How to show more than 5 posts?

I think you could use the posts_per_page argument in your get_posts query: $args = array( ‘child_of’ => 1 ); $categories = get_categories( $args ); foreach ($categories as $category) { echo ‘<li><a>’.$category->name.'</a>’; echo ‘<ul>’; $posts_args = array( ‘posts_per_page’ => 9, ‘category’ => $category->term_id ); foreach (get_posts($posts_args) as $post) { setup_postdata( $post ); echo ‘<li><a href=”‘.get_permalink($post->ID).'”>’.get_the_title().'</a></li>’; } … Read more

Check if post exists

WordPress has a post_exists function that returns the post ID or 0 otherwise. So you can do if ( 0 === post_exists( $title ) ) { **YOUR_CODE_HERE** }

Conditional to modify query results

here is the mysql query you can use to get the result having distance less then your value. SELECT * , pm1.meta_value as latitude, pm2.meta_value as longitude , (((acos(sin(([latitude]*pi()/180)) * sin((pm1.meta_value * pi()/180)) + cos(([latitude]*pi()/180)) * cos((pm1.meta_value * pi()/180)) * cos((([longitude] – pm2.meta_value)* pi()/180))))*180/pi())*60*1.1515 ) as distance FROM wp_posts p JOIN wp_postmeta pm1 ON pm1.post_id … Read more

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