It’s not necessary to use $wpdb
, a simple get_posts
can handle it. Check WP_Query
for the full list of parameters.
function count_user_posts_by_type( $userid, $post_type )
{
$args = array(
'numberposts' => -1,
'post_type' => $post_type,
'post_status' => array( 'publish', 'private', 'draft', 'pending' ),
'author' => $userid
);
$count_posts = count( get_posts( $args ) );
return $count_posts;
}
Related Posts:
- Is it possible to cancel a post status transition?
- Fatal error “Call to undefined function is_plugin_active” each time the plugin is activated
- The Build menu theme is frozen with the wordpress theme
- Shortcode do not return the right data in post
- Add style to body based on url
- function post to trash problem
- Problem with checked box on wp car manager plugin
- How to call function in WordPress on button click?
- how to auto random increment for post view
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- Access “wp site health info” data from plugin
- Ultimate Members Default Post Layout problem
- Fatal error: require_once(): Failed opening required
- WordPress Frontend Page using Plugin
- best way to upload a large file to wordpress using wp all import
- Why do actions with class and public method don’t fire __construct()
- How to properly enqueue jQuery knob on WordPress without conflict?
- Potential issue that plugin could have when it will be installed on several sites
- show wc_add notices on particular page in woo commerce custom plugin development
- How to use functions found inside pluggable.php with my plugin files
- How to overwrite a plugin?
- Getting the same post on my related post
- The function called on the wp head hook becomes null
- Hide content for specific users with id
- adding dynamic/multiple slug values in ‘option_none_value’
- Is it okay to make a plugin to the WordPress repo, but limit it’s actions to maximum N events?
- How can I translate something in my class constructor of my plugin in WordPress?
- custom post type get_posts() function not work
- I want to schedule email (date, time is in database->table) wp_schedule_event() not working
- Error on plugin activation and creating new page
- Child theme modifications not showing up
- Create multiple posts when a custom post is created
- Define global variable in theme file and call that variable in plugin file
- Highlight admin menu items that are parent of existing core items
- How to create a page with the selected template after activating the plugin
- Why is my shortcode not working?
- WordPress rewrite rule depend on meta values not ids
- Update wordpress user roles not working as excepted
- Create new page in wordpress plugin which doesn’t exist
- Use WordPress Plugin without WP head
- Adding shortcodes to multiple pages with function
- Rename a folder via HTML POST request
- The plugin generated 227 characters of unexpected output during activation. If you notice “headers already sent” messages
- SASS not showing in customized preloader plugin
- How to capture hidden values with Gravity Forms
- How to securely controlling data without keeping it in postmeta?
- The styles in the recent posts widgets plugin not working
- How to change “Read More” text?
- How to call a function from class in wp table list button form
- How to translate to spanish wordpress hardcoded content/files?
- Cron task gets removed from the schedule
- what functions to use to resize images and create DB metadata for them after/during upload?
- How to get the checkout form data from checkout page when place-order button is clicked
- Woocommerce convert simple products to variations
- Getting Fatal error: Uncaught Error: Call to undefined function plugin_dir_path() when linking to another file within my wordpress plugin
- $wpdb->insert not working inside save_post tag
- How to check for already existing plugin versions on activation? and prevent errors
- update_post_meta is not working for me when I use e.preventDefault for update button
- How to make WooCommerce multiple filter with custom meta fields
- how to add a hidden type input to wp admin login form programmatically
- How to create a plugin with automatic update?
- How can I see $post object in frontend from functions.php?
- Create a link that calls our custom function in WordPress
- Move plugin pages from dashboard to front-end
- working code, not working – Plugin Dev
- Allow members to create groups on my site
- category page multiple products add to cart any plugin available for woocommerce
- WordPress UPDATE queries on MySQL database stuck
- Cannot view Custom Post Type no matter what I try
- How to remove WordPress Default Comment? not Facebook
- SimpleXML is not working with xml response from external api
- How to use Datatable with Ajax when creating plugin on WordPress?
- Custom Plugin Update
- Getting all woocommerce products from REST API call in plugin
- Creating one user access account for all the multiple sites
- is it possible to fetch data from a remote api while admin is writing a new post?
- how override a define
- WordPress plugin blog creation
- How do I stop plugins and themes from getting updated in a new plugin?
- Preserving existing functionality converting HTML to WordPress
- I enabled debugging but I still get the same message: There has been a critical error on your website
- Problem with wordpress has_action() function
- wp_mail function not working in WordPress Plugin Boilerplate
- How come W3TC is allowed to host premium code in the WordPress repo?
- When/where would want to attach other classes to the base class in a WordPress plugin?
- Link custom post type to page
- Offering a freemium plugin (a free version + paid version)
- Using id to show item
- add tags to wordpress post using REST API
- Multiple image selection custom widget
- implement checkbox or toggle switch in plugin code
- 500 Internal server error wp_handle_upload_prefilter
- path of wp-content directory when we are on some plugin
- Using foreach loop for `$instance` of form and update array widget iteration
- How to use wp_editor and save its data in wp_posts table
- How to call a function from inside class to outside class
- My WordPress activation hook isn’t working
- How to Create a Learning Management Plugin in WordPress to Manage Courses [LMS]
- “Enable Media Replace” plugin does not update serialized object in WPMeta
- One time call to external API in widget