You can run a query using get_posts
to retrieve posts from a specific author, and exclude certain categories, and then use count
to return the amount of posts. get_posts
uses the same parameters as WP_Query
, so you can have a look at the parameters there
<?php
$args = array(
'author' => 1 //ID of the author
'posts_per_page' => -1, //Retrieve all posts
'category' => -13, // Category to exclude, must be ID, as category is passed to WP_Query as cat
);
$posts_array = get_posts( $args );
echo count($posts_array); //Display post count
Related Posts:
- What happens if I delete all the rows that represents a post revision from the posts table into WordPress database?
- How to add an admin notice upon post save/update
- Passing current cookies in wp_remote_get to get Draft Post Preview
- MySQL Query to Retrieve Category from wp_posts
- SQL Query for getting all posts in their latest revised state
- Listen to Post action
- Manipulate post category after time
- Search & Remove Specific Shortcode From All Posts
- Manually delete post from database
- WooCommerce – Create Products Programatically [closed]
- How to force update all posts after import
- which action to hook to in order to perform post-publish action
- Cannot access current post’s ID in custom plugin
- Set number of article per number of page
- How to change post status from publish to draft using hook in wordpress?
- prevent showing posts of an specific category in admin posts section
- Query All users that has post
- Using radio button meta data from a custom meta box
- Can’t publish new posts
- Manually removing revision post types
- Reset/Reorder posts ID in the MySQL wp_posts table
- How to store an extra (surrogate) ID when creating a post with wp_insert_post?
- Global $post not working in OOP function WordPress
- How do I find which articles are missing a featured image in The WordPress database?
- Tags to Post-ID mysql query. Tag Search
- Define a wordpress constant through plugin functions?
- How to get post bulk edit action trigger and get edited post ids?
- wp_insert_post – duration
- updating a post doesn’t trigger a function
- Hide a specific category in admin All Posts page (WordPress)
- Prevent Delete Attachment by URL or When Submit
- What hook do you use to update a post?
- Updating post data on save (save_post vs wp_insert_post_data)
- Get user categories with most posts in it
- MySql query to get posts with all meta and terms
- Custom order for Mysql array
- List authors with the last post title and order by last post date
- How to Mysql select a list of posts with meta_values AND all relevant categories?
- Remove a shortcode from all WordPress posts
- Order posts alphabetically: how to set order=asc in mysql query?
- What do these phpMyAdmin errors mean on my WordPress databaes?
- Delete post results in “Cannot delete or update a parent row: a foreign key constraint fails”
- Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
- update image path with words starting uppercase to lowercase chars
- Filter Hook for post table (not columns)
- why str_replace targeting pages instead just targeting post?
- Queries take 120+ seconds on my large WordPress site
- Database hacked – random posts are modified
- Need to change all links in page content but not in post content
- Can’t update WordPress Page if post_content is Empty
- Restore woocommerce orders
- How to select particular month post from table and update the post status using MySQL?
- How do post IDs work in WordPress?
- Stop post submission without losing data?
- Cant’ Grab WordPress Built-in Posts Through Loop
- How can my plugin display a populated new post window
- search content of pages and list in wp-admin
- Finding a post’s slug
- Insert specific information to a posts of a predefined category
- Open a wordpress single post in a lightbox without the header and footer
- get last post’s link with SQL query
- query for filtering published posts?
- MySQL: Possible to replace all of wp_posts.post_content(id#) via UPDATE + REPLACE + SELECT?
- Deleting post tags removes categories
- Return records between two meta datetimes saved as strings
- WP query taxonomy optimization
- MYSQL: Create SQL query to search for string and replace
- Query to fetch custom taxonomy along with post title
- Mysql update menu_order problem
- WordPress: Develop multiple posts with different data
- Bulk find & replace on WordPress posts/pages (minus image paths)
- WordPress MySQL Search and replace with wildcard?
- Add postmeta to all blog posts
- ‘posts’ table should not store the absolute image path
- Dev and prod on the same database- dev version active for IOS
- load post data into mysql
- How do I change the post title’s link on the posts page?
- Update user meta when post published no working
- SQL trigger failes with post_content
- Fixing the WP Post Object for Custom Route
- Export Posts with specific custom fields by sql
- Custom plugin to get related posts by category
- Converting Posts to Pages
- How to change the publishing date of each posts?
- SQL query to remove first image in all posts
- Delete junk text from all the post using my sql command
- FIND and REPLACE wp_posts AND IGNORE custom post type mysql query
- How to create a post based on data in a table?
- Hide the contents for specific post
- If meta_key exists then don’t select this post?
- Error 404 blog/page/2/
- Onclick open posts displayed in slider in a popup [closed]
- How do I save JS classes being applied to the WP dashboard via custom plugin?
- How to update wp_posts with just the returned comment count from wp_comments (SQL GROUP BY)
- Custom Field in Featured image for A particular post
- add_action not using ‘delete_post’ action with wp_delete_post
- Getting post id from wp_insert_post_data function?
- Getting featured image with PHP and not javascript from wordpress api _embed [closed]
- WordPress Query – Display 5 posts (same post type), each from a given tag
- get_the_ID() fails the first time, returns a value the second time it’s called