The problem you are having is that get_queried_object returns results based on the query that was run.
On author.php, the queried object was an author.
On single.php, page.php, or any custom post type template, the queried object will be the post, not the author.
This means that if you want to use $wp_query->get_queried_object();
, you will have to be aware of what kind of object you re grabbing … and possibly do other things if your object is a post or a page.
e.g.
$post = $wp_query->get_queried_object();
$author_id = $post->post_author;
$post_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author="" . $author_id . "" AND post_type="campaigns" AND post_status="publish"");
For term pages, post archive pages, etc., you might need to do such inside of the loop by grabbing the current post object, reading the author, and then grabbing that authors counts.
Related Posts:
- Want to filter only parent post in admin area
- wpdb custom post_type problem
- convert custom query to wp_query
- Converting the_content string to an array?
- foreach loop inside the loop creating duplicates in output
- How to use costum database table for custom post type
- Create a WordPress Database query to find users who purchased specific product through WooCommerce [closed]
- Query by post title
- Get post with multiple meta keys and value
- Get posts for custom post type with WP_Query
- WP_Query() show posts that end later than today
- How to check if a WP_Query has data
- Sorting a query by custom field date
- Number of pages – multiple (custom) post types
- Enforcing canonical URLs with multiple custom post types
- WP_Query -> sort results by relevance (= most tags / taxonomy terms in common)
- Retrieving 3 latest post from each of 5 different custom post types
- Get latest 4 post on a custom post filtered by category
- how to group custom post type posts by custom taxonomy terms
- How to sort CPT by custom meta value (date), and return posts month by month
- wp_query and comment_parent – select only posts with top level comments
- Comparing timestamps in meta query doesn’t work
- Include both default and Custom Post Type in query modified inside pre_get_posts
- $wpdb returns no results with SELECT query on custom post type, works on default post type
- List all custom post type posts from a given category?
- Exclude current post when getting related post on custom post type and taxonomy
- Display Posts of a Category in Alphabetical Order (Custom Post Type)
- Ordering Custom Post Types with WP_Query
- Filter posts with meta_query NOT IN where value has multiple values
- How to query different post types in specific order?
- Loop on front-page.php
- Querying Term Posts in Loop
- is_main_query() not working for WP REST API
- Can’t get order_by meta_value_num to work properly
- Taxonomy Archive: Display only one post per term from separate custom taxonomy
- orderby in custom WP Query does not work
- Unable to retrieve any posts of CPT in wp-admin
- Linking to the most recent post in a Custom Post Type
- How to make sure content doesn’t display if selection is empty
- Creating a navigation menu of all posts of a custom post type and their children posts?
- using $wpdb to get custom post type with term
- Wp_query: sort by PHP variable
- WP_Query most viewed posts, in multiple Post Types, last 30 days, excluding a specific taxonomy term
- Crafting WP_Query array, sort by date
- Including metaboxes from custom post types in global search — continued
- Custom Widget WP_Query problem
- Order posts by 2 custom fields and if one custom field is zero orderby another custom field
- WP Query post__in not returning correct results
- Proper way to display latest 5 posts grouped by post type?
- Detect inside a custom query the kind of post type to assign custom classes
- Custon Content within WordPress Loop
- WP Query ‘posts_per_page’
- Custom taxonomy wp_query woes.
- Trouble with pagination
- Select2 AJAX and WP Query Returns ALL and does not filter
- WP_Query orderby not work with meta_key
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- Different options per post type in WP_Query
- Returning a custom content types with meta values
- Custom Category Walker with Image, Fallback to Most Recent Post in Category Image
- List categories, subcategories and posts from custom taxonomy and custom post type
- Custom Post type loop with ACF not displaying properly
- Sort results without WP_QUERY?
- Using Wp_Query, Json to add Highcharts series data
- Display the current post in browser as the first post in a loop (for a slideshow)
- Searching post types
- How to retrive Custom Post Type Meta Fields in Custom WP_Query
- wp_query not returning my custom post
- filter the_content, custom post type, and wp_query
- Loop for custom-post-type comparing taxonomy terms for “related” posts?
- custom taxonomy pagination 404 error
- wp_query can’t get max_num_pages in custom post type
- Custom Form / Search with Custom Post Type Data
- Get next and prev item from custom WP_Query and Custom Post Type
- After inserting new post with wp_insert_post() the post is not visble to WP_Query, but the same WP_Query works for post inserted from wp-admin panel
- Query to show post current day
- Using ACF values in nested WP queries for CPT with date values in the past
- WP_Query: how to search tags in addition to a custom post type?
- Pagination Not Working When Used With WP_Query() `offset` Property
- Filter in Custom post type to find the parent post
- Help understand and create a loop with WP_query
- WP_Query for custom taxonomies showing posts from non-specified terms?
- Make pagination work as a carousel (custom query)
- WP_Query with all posts in one custom post type and only posts in another custom post type with a specific category
- Search result based on URL
- subtracting the current post form then whole loop, which is generating all CPT titles
- Imported Content Doesnt Show Up On Frontend
- Loop carousel slider in wordpress
- Manually build WP_Query
- New WP_Query not isolating custom post types on front-page template
- How to load more custom type posts through AJAX & LOAD MORE POSTS button
- Pagination always adding “Next” link when results come from Custom Post Type WP_query
- 404 on Pages for Custom Post Type & Query_Posts
- Pagination not working on homepage
- How to query custom post then display sections by meta value
- Using tax_query to get single post per category
- Show Posts in Vertical Tabs with Scrollbar
- How to manage wordpress knowledge base/wiki/posts collections
- Is it possible to make is_category() recursive?
- Get X posts with the same terms as the current post (custom post type and custom taxonomy)