Get_post() with meta_key when compare is a date

I think you have error in your query. Please try this: $posts = get_posts(array( ‘post_type’ => ‘events’, ‘posts_per_page’ => -1, ‘meta_query’ => array( ‘meta_key’ => ‘from_datetime’, ‘type’ => ‘DATETIME’, // You can also try changing it to TIME or DATE if it doesn’t work ‘meta_value’ => date( “F d, Y g:i a” ), ‘meta_compare’ => … Read more

Is it better practice to use query_posts, WP_Query, or get_posts to create various custom loops within a Page?

Hi @janoChen: If you have a choice, go with WP_Query. Both of the other functions (query_posts() and get_posts()) call WP_Query indirectly. The former is designed to allow you to modify the main query after the standard query has already been run, for example when you want a second loop. But query_posts() affects global variables and … Read more

How to get_posts having post thumbnail?

The thumbnail is stored as a meta with a key of _thumbnail_id, so that could be used to find posts that have thumbnails. Something like this: $query = new WP_Query(array( ‘meta_query’ => array( array( ‘key’ => ‘_thumbnail_id’, ‘value’ => ‘0’, ‘compare’ => ‘>=’, ) ) ));

get_posts inside cron

Whenever you do get_posts or WP_Query or anything like that, it’s important to remember that the code is actually getting all of the Posts at once, and loading them from the database into memory. If you run out of memory, then your process will simply die with an error. Attempting to get very large numbers … Read more

How to retrieve a value from get_posts()? [closed]

Each post is an object, which changes the syntax you need to use to access the post name: $arr = get_posts(); $arr = array_reverse($arr); foreach ($arr as $post) { echo $post->post_name; echo “<br/>”; } As a side point, a slightly easier (and computationally more efficient) way to get your posts in reverse order is to … Read more

How to display posts by current user/author in a custom page template?

this should work for you: if ( is_user_logged_in() ): global $current_user; wp_get_current_user(); $author_query = array(‘posts_per_page’ => ‘-1′,’author’ => $current_user->ID); $author_posts = new WP_Query($author_query); while($author_posts->have_posts()) : $author_posts->the_post(); ?> <a href=”https://wordpress.stackexchange.com/questions/23829/<?php the_permalink(); ?>” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a> <?php endwhile; else : echo “not logged in”; endif;

Query posts ordering by title, but ignore ” and special characters

Try this… $posts = get_posts( array( “orderby”=> “slug”, “order” => “ASC”, “post_type” => “my-custom-post-type”, “posts_per_page” => -1, “fields” => “ids”, “meta_query” => array( array( “key” => “ams_park_id”, “value” => get_the_ID(), ) ) ) ); Noticed I changed “orderby”=> “title”, to “orderby”=> “slug”. Typically the slug will be close to the title but all of the … Read more

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