Check If posts exist in custom post type category, outside of loop

It all boils down to WP_Query in the end even if you use get_posts, here’s my modified version: $hasposts = get_posts(‘post_type=sc-events&category=40’); if( !empty ( $hasposts ) ) { ..// show the drop down menu } or $query = new WP_Query(array( ‘post_type’ => ‘sc-events’, ‘category’ => 40 )); if( $query->have_posts() ){ echo ‘we have posts’; } … Read more

Count posts returned by get_posts in external PHP script

The WordPress function get_posts() is making it’s own instance of WP_Query that is not globally accessible: function get_posts($args = null) { // … cut … $get_posts = new WP_Query; return $get_posts->query($r); } so you could instead try $results = get_posts($args); echo count($results); to give you the array count of post objects returned by get_posts(). WP_Query() … Read more

How to query custom post type by term?

You cannot make up your own arguments – rather than replacing the ‘category’ argument with your taxonomy name, use ‘tax_query’. See “taxonomy parameters” section of the codex on get_posts. $args = array( ‘post_type’ => ‘event’, ‘post_status’ => ‘publish’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘eventcategory’, ‘field’ => ‘slug’, ‘terms’ => ‘nice-events’, ), ), ); $your_query … Read more

WordPress get posts by date without query_posts

Yes, simple add a filter before you call it and remove it after you do function filter_where_wpa89154($where=””) { //posts in the last 30 days $where .= ” AND post_date > ‘” . date(‘Y-m-d’, strtotime(‘-30 days’)) . “‘”; return $where; } add_filter(‘posts_where’, ‘filter_where_wpa89154’); $args = array( ‘posts_per_page’ => 5, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘suppress_filters’ … Read more

How to get only one category of custom post type?

Never use query_posts! Use get_posts() or new WP_Query() instead. I think this will work however: $today = date(“Y/m/j”); $args = (array( ‘post_type’ => ‘event’, ‘posts_per_page’ => 10, ‘orderby’ => array( ‘wpse_meta_query_name’ => ‘ASC’, ‘post_title’ => ‘DESC’ // optional second orderby paramater ), ‘meta_query’ => array( ‘wpse_meta_query_name’ => array( // give the meta query arguments a … Read more

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