How to Get Posts, Including Private Ones?

Set the post_status argument to an array of desired post status strings, or to the string any to query regardless of status entirely: $posts = get_posts(array( ‘posts_per_page’ => -1, ‘post_type’ => ‘post’, ‘post_status’ => array( ‘publish’, ‘private’ ), ));

Custom query for custom post_type

change your query a bit: $todays_date = time(); $args = array (‘post_type’ => ‘tasks’, ‘meta_key’ => ”end_date, ‘meta_compare’ => ‘<‘, ‘meta_value’ => $todays_date, ‘orderby’ => ‘meta_value’ ); $tasks = get_posts($args); and then for each one of this posts get the start_date meta and compare with $today something like: $today = strtotime($today); foreach ($tasks as $task_post){ … Read more

PHP Syntax Error on get_posts

Not sure if it is causing Dreamweaver to flag an error (try running it?), but on the second from last line you want to be using get_the_title(). This returns the posts’ title, whereas the_title() will echo it. echo ‘<a href=”https://wordpress.stackexchange.com/questions/44471/.the_permalink().”>’.get_the_title().'</a><br />’;

While loop articles – if statement order

Prepare the query before you loop over it: $first = array_shift( $the_query->posts ); $second = array_shift( $the_query->posts ); // now re-add in reverse order array_unshift( $the_query->posts, $first ); array_unshift( $the_query->posts, $second ); // this is now the first item while ($the_query -> have_posts()) : $the_query -> the_post(); // regular loop

How to get posts and comments amount per hour, per year and per month?

For comments: function count_comments_in_period( $date_from, $date_to ){ global $wpdb; $count = $wpdb->get_var( $wpdb->prepare(“SELECT COUNT(*) FROM {$wpdb->comments} WHERE comment_date >= %s AND comment_date < %s “, $date_from, $date_to)); return $count; } Just use dates in yyyy-mm-dd format. For posts: function count_posts_in_period( $date_from, $date_to ){ global $wpdb; $count = $wpdb->get_var( $wpdb->prepare(“SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_date >= … Read more

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