Show Two custom Post type and their posts on category page

First, I would recommend making this change in Category.php file, as archive.php is affecting tags as well as other archives according to WordPress Theme Hierarchy file system. Try adding the two queries like next: $cats = get_the_category(); $cat_id = $cats[0]->term_id; // news $args = array( ‘post_type’ => ‘news’, ‘posts_per_page’ => 5, ‘cat’ => $cat_id, ); … Read more

Get posts by multiple ID’s (query)

Did you look at the documentation for WP_Query? The p parameter takes only a single integer. Use post__in. $args = array( ‘post__in’ => array( 206, 189 ), ‘post_type’ => ‘product’, );

Only display posts after current date

Turns out meta_query was the way to go. This is the code I used to make it work. add_action( ‘pre_get_posts’, ‘filter_posts’ ); function filter_posts( $query ) { $now = date(“Y-m-d H:i”, strtotime(‘+2 hours’)); if( is_category() && !is_admin() && $query->is_main_query() ) { $query->set( ‘posts_per_page’,’10’ ); $query->set( ‘orderby’,’meta_value_num’ ); $query->set( ‘meta_key’,’date-start-custom’ ); $query->set( ‘meta_query’, array( array( ‘key’ … Read more

Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX

Because of this line: $paged = get_query_var( “paged” ) ? get_query_var( “paged” ) : 1; This is inside a function that is used on both an AJAX handler, and on a page request. get_query_var pulls the parameters from the main query ( aka the primary WP_Query that powers functions such as the_post, have_posts() etc ). … Read more

Count how many posts have a custom field set

You could run a custom query to count the amount of posts with a given key using $wpdb or more specifically using get_var(). If i assume you want to count published posts with a given key, then something like the folowing should do it..(though this is just an example). function get_meta_count( $key = ”, $type=”post”, … Read more

$wpdb doesn’t appear to work on page inside of a plugin

The $wpdb object is part of WordPress, so wouldn’t be loaded into a standalone PHP page as it is into a WordPress template. You might want to look into creating your own page templates, then you could run your database query as part of that page template. As a side note: You are currently trusting … Read more

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