If you prefer the $wpdb direct queries you can use something like this:
global $wpdb;
$count = $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_type="code" and post_status="publish"" );
echo $count;
In the sql query above change the post_type
to whatever you like. This will return count of published posts under specific post type only.
If you want to query counts from multiple post types do this query:
global $wpdb;
$count = $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_type IN ( 'code', 'shop', 'post', 'etc' ) and post_status="publish"" );
echo $count;
Hope that helps.
Related Posts:
- Inject post (from specific category) between posts in Loop
- Get taxonomy terms only of the WP_Query current posts
- Remove query string specific key value
- Hide post if matches current month and year
- How can I use wp_query to show all product data using just the products ID?
- How to store post ID’s in cookie or session to display the same posts later
- WP_Query: getting posts where custom field exists
- Array to string conversion on array_map
- Store metakey value as an array
- Increment paged on WP_Query
- Modify main query before it run without pre_get_post
- Do not duplicate posts with multiple categories in multiple loops
- array_rand not working correctly?
- WP_Query() load selected post
- Wp Query : Order by distance lat,lon
- WordPress sorting posts by date and title using a dropdown
- posts_per_page displays only 2 posts instead of 4 posts
- Query on a repeater date (acf)
- Need to show 7 posts from actual date
- Check the database for a postmeta field
- Getting info about selected posts using one WP_Query
- How to display last whole post on the homepage
- Get the total Author Favorited posts
- For each 3 posts, show a different post type
- Only Get A Certain Number of Posts From WP_Query
- insert thumbnail image from php script
- WP_Query count of different meta key values [duplicate]
- Weird Behaviour: Not all WordPress Posts appearing
- List of child pages fetch next results at link click
- Query category-specific, paginated posts and allow viewer to change sort order
- Why does WP_Query show only the same post even with different categories and endwhile?
- How to modify this function to exclude also the post belonging to a specific category?
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- Count the number of matching post names in foreach loop
- get_the_content if it contains multiple lines it results in SyntaxError
- Looking to exclude blog posts from category Previous/Next buttons
- How do I add a php statement to a jQuery string
- Automatic Excerpt Not Working
- WP_Query with the “offset” argument
- How is WordPress manipulating the posts like there are folders?
- WP_Query is printing out only one post when posts_per_page is set to multiple
- Get the last month with posts using a recursive function…
- How to query for pages/post depending on slug?
- wp_query with cat not working
- How do I “get the next 10 posts after post_id == x”?
- Recent Posts slider, using WP_Query(), loads duplicate sliders
- Why WP_Query(‘showposts=5’) shows only 1 post?
- Compare post-IDs within WP_Query? (Less than / Greater than)
- How to use $query->set with post__in?
- Display a specific category of products in shop page and disable code for specific actions
- Which hook/action will help me solve my problem?
- Custom query, checking values of multiple meta keys
- Get children post mime type using parent post_ID wp_post
- Redirect to another page using contact form 7? [closed]
- Fatal error: Call to a member function query() on a non-object
- Is it possible to retrieve all posts with a certain value for metadata?
- How to avoid duplicates when creating recent network posts
- Update post title from external file?
- set post limit at load more ajax wordpress
- Trouble inputting variable into WP query
- WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank
- How to use mysql LIKE with wpdb?
- Get all posts as an array ID => Name
- Do I need to edit my theme in order to change the title of my blog page?
- Passing an array into WP_Query as a variable
- WordPress meta_query >= &
- Incrementing PHP variable onclick to display posts by month
- Dividing the loop to style post differently
- WordPress Search
- Displaying Event within two given time frames
- Remove Post if Advanced Custom Field is checked to fix paging
- Output product category link from WP_Query
- Counting number of posts in multiple (sub)categories using shortcode
- Edit and delete permissions pages and posts
- Post form – AJAX won’t upload featured image – Plugin development
- Load more posts using AJAX based on posts inside WP_Query
- Custom search query on WordPress page not working
- Like and Dislike Buttons on Post with Counter – Only allow one click per post per user session
- How to select post ID for given parent name with nested prepared queries?
- WordPress recent post
- Add code to the header of posts by particular author
- Can I disable auto increment of WordPress Posts Database to utilize previously deleted records?
- Get Child of Child Pages in custom Menu
- My blog posts section seems to be rendering the other blog posts inside the first? :/
- Meta query not showing result properly
- LinkedIn Share Post Button
- problem in using wpdb->prepare and a string placeholder
- Help on Wp_query to print an term
- making a search.php query
- How do I generate formatted permalinks as specified in backend options?
- Efficient way of querying for a “fallback” post?
- Create a hierarchical loop at predefined markup requirements
- How do you detect if a specific word is at the end of a the_title()
- Keeping the previous get value and add another value when submitted
- link to page_for_posts
- Pagination in category.php not functioning
- $post->ID calls for current page, but what is the code to call for any new page created and published in WordPress?
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- How to sort search result by post_title, then by post_content
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress