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

Post query – show posts from specified day and month and whole years

You can use WP_Date_Query in conjunction with WP_Query to accomplish this. $query = new \WP_Query( array( ‘posts_per_page’ => 5, ‘date_query’ => array( array( ‘day’ => date( ‘j’, current_time( ‘timestamp’ ) ), ‘month’ => date( ‘n’, current_time( ‘timestamp’ ) ), ‘before’ => ‘this year’ ) ) ) ); if ( $query->have_posts() ) : while ( $query->have_posts() … 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

Multiple choice in a custom taxonomy

To display multiple authors, loop through the array of authors: function show_product_autor(){ $authors = wp_get_post_terms( get_the_ID(), ‘autor’ ); foreach($authors as $author) { $authorTeamPg = get_page_by_title( $author->name, ‘OBJECT’, ‘team’ ); $authorTeamPgLink = get_permalink( $authorTeamPg->ID); echo “<b>AUTOR: </b><a href=”https://wordpress.stackexchange.com/questions/289422/{$authorTeamPgLink}”>{$author->name}</a>”,'<br />’; } } To handle editors, the simplest solution IMO would be to make the taxonomy heirarchical and … Read more