Query total number of posts

How could I get the static total number of posts which wouldn’t change irrespective of what the user filters? You may be looking for wp_count_posts(): Codex: WP COUNT POSTS Example getting number of all published posts: function get_all_them_posts(){ $count_posts = wp_count_posts(); $published_posts = $count_posts->publish; return $published_posts; } In template: <?php echo get_all_them_posts(); ?> For Custom … Read more

tax_query: Order by slug?

If I understand your scenario, your events are in the right order but your semesters are not. If you change line 4 $terms = get_terms(‘semesters’); to $terms = get_terms(‘semesters’, array( ‘orderby’ => ‘slug’ ) ); that should put the semesters in the order you’re looking for. ‘order’ defaults to ASC, which is what you need … Read more

How to correctly pass values to wpdb->prepare()?

I’ve found an answer by myself.. (sample code) $args_array = array($post_type); $term_slugs = array(‘foto’, ‘video’); // create a string like ‘%s, %s’ ecc $placeholders = implode(‘, ‘, array_fill(0, count($term_slugs), “%s”)); $term_query = “t.slug IN ($placeholders) “; $args_array = array_merge($args_array, $term_slugs); $ids = $wpdb->get_results($wpdb->prepare(” SELECT m.meta_value FROM ” . $wpdb->prefix . “posts p INNER JOIN ” … Read more

Query post from all category with same tag on 1 pages

This will help to get the category post on tag archive page. Let me know. <?php $current_tag = single_tag_title( $prefix = ”, $display = false ); $categories = get_categories( array(‘hide_empty’ => TRUE) ); foreach($categories as $category) { ?> <?php $args=array( ‘posts_per_page’ => -1, ‘tag’ => $current_tag, ‘cat’ => $category->term_id, ); $the_query = new WP_Query( $args … Read more

Pagination is broken and I need help fixing it

I’m not sure why the first page works but the second doesn’t, though this may be a hint toward the problem. Toward the bottom of the category template page you have the following: if (function_exists(custom_pagination)) { custom_pagination($custom_query->max_num_pages,””,$paged); } If you review the above, there is a variable called $custom_query. This looks like it’s a WordPress … Read more