admin-ajax.php
is treated as part of the admin, so protected statuses will be included. To solve this just explicitly define post_status
as publish
to only get published posts:
$args = array( 'post_type' => 'project', 'post_status' => 'publish' );
Or, better yet, consider using the REST API for AJAX requests, instead of the aging admin-ajax.php approach. If you want to query a custom type and receive JSON then you probably don’t even need to create your own endpoint.
Related Posts:
- AJAX search on post pages by custom post type
- How to use a custom post type as front page?
- Querying Posts by Taxonomy From Alternate Network Site
- Query by 2 values of a repeater ACF field
- Comparing timestamps in meta query doesn’t work
- Display two post types ordered by two custom fields
- Include both default and Custom Post Type in query modified inside pre_get_posts
- Having trouble with custom date field for CPT query (WordPress)
- WP_Query search posts by custom post type and custom taxonomy
- Calculating Bayesian average for custom post type
- Conditional to modify query results
- Is it possible to create a shortcode that will query a post based on taxonomies?
- Querying Term Posts in Loop
- Use get_post_types to query only custom posts types
- WordPress Orderby Numeric Value Not Working
- Filtering WP_Query Dynamically on the Front-End
- Why get_posts() not returning only selected category posts from Custom Post Type?
- Storing posts from query and accessing later via AJAX call
- convert custom query to wp_query
- Search / Filter posts on Title/Content OR Tags
- WP_Query inside foreach loop returning same value for all options when filtered using ajax
- creat filter with wp_query
- First custom field value (out of several) displayed twice after query
- Prioritize posts in query by meta keys?
- WP_Query orderby and tax_query
- Different Ways to Query Custom Post Types?
- Pagination with custom query, custom search form, single and pages, ajax and no plugins
- Retrieve custom post types by custom taxonomies with WP_Query
- Showing specific post in order of array wp_query
- WP_Query() with custom post type and taxonomy — get all terms?
- Select2 AJAX and WP Query Returns ALL and does not filter
- Returning a custom content types with meta values
- Create query for both custom post type and category
- Query custom posts from custom taxonomy
- Display custom-post type based on the Title matching the current selected value
- Is there a (preferable built-in) way to check what custom queries are used in a theme?
- Change search query in wordpress custom post type
- WP Query from two Custom Post type fields as statement
- WP Query: If field X is empty, show posts based on field Y
- Filtering posts based on three taxonomies
- How select query is generated in a Custom Post Type?
- WP_Query for custom taxonomies showing posts from non-specified terms?
- WP_Query with all posts in one custom post type and only posts in another custom post type with a specific category
- post type => ‘any’ not applied my custom queries
- Ajax load more inside custom post type taxonomy
- Linking posts together with Advanced Custom Fields “both ways”
- Get posts of an specific term of a custom taxonomy
- Conditional posts in WP_query for search
- Query Pulling the same post twice
- Is it possible to add query parameters on the archive page?
- How to load more custom type posts through AJAX & LOAD MORE POSTS button
- Query child posts on parents single.php?
- Query Posts From Multiple Post Types
- WordPress can only query up to 766
- Filter Custom post type by another Custom post type
- Create a list of months based posts
- Query Multiple Post Types and Paginate Newly Created List
- How to show CPTs in term archive
- Query custom post type by category slug
- Custom query to filter posts that have current post as a taxonomy [closed]
- Combining sorted and random CPT
- How to add post_type=value when editing that post type in the WordPress admin?
- Display CPT posts based on specific taxonomy
- Can’t query tag and post_type at the same time
- Setting proper query for multiple custom admin filters
- shortcode to show custom post types by category
- Ajax Check Post Status
- Unable to retrieve any posts of CPT in wp-admin
- WP_Query: include custom post type only with specific meta value
- Pagination on a custom post type loop
- showing custom post types of a certain category only
- WP_Query orderby modified to include custom meta changes
- WordPress custom loop filter by meta_key and value with serialize data
- Am unable to reset a query properly
- Returning a list of custom post types excluding those without a specific meta_value
- query private custom post type
- Display custom post type from dynamic custom field
- Query/list all terms and their custom post count
- Linking to the most recent post in a Custom Post Type
- Received nothing after executing AJAX post function
- How to make sure content doesn’t display if selection is empty
- Custom post type redirected to homepage – how to debug
- How to modify archive query with pre_get_posts to append CPTs?
- Show one item per category of a custom post type
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- Archive for custom taxonomy lists all posts instead of current taxonomy
- Genesis filterable portfolio isotope [closed]
- Loading custom content type from ajax results?
- Query custom post type with tags
- Get next and previous 3 posts in a term in single post page
- wp_query check if integer exists in custom field’s array
- Wrong request query on cpt and tax
- Previous/Next Link by Meta Value in CPT
- Show custom post type filtered by category
- Randomize Posts. Skip the first post in ascending order
- Creating a navigation menu of all posts of a custom post type and their children posts?
- Get custom taxonomies from multiple posts
- Making certain categories of CPT not publicly queryable
- Pagination for Custom Taxonomy Page [duplicate]
- Filtering WP_Query