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
- Mixing regular and custom post types (with meta_query) on home page
- Sort custom post type list table by display name of a user id stored as post meta value
- Use WP_Query object inside a function
- WP_Query search custom posts meta date fields
- Get posts with tag all post types
- Using new WP_Query in shortcode in a custom field causes the main post content to not display
- query order by date on custom type: wrong order
- Help with CPT template pagination
- Custom query shows custom post types in trash
- How to connect two custom post types with nested loops
- Custom Post type and Custom Field WP_Query
- Display multiple custom post types and sort them chronological by one of their fields
- Using DISTINCT in wp_query
- Order By Post Type ThenBy Taxonomy
- How to show CPTs in term archive
- Custom query to filter posts that have current post as a taxonomy [closed]
- Query/list all terms and their custom post count
- Received nothing after executing AJAX post function
- How to modify archive query with pre_get_posts to append CPTs?
- Pagination on with query_posts in custom post type template
- Polylang non-default language ignores tags in WP_Query
- Load Custom_post_type categories post with ajax
- wp_reset_postdata() and wp_reset_query() inside shortcode are not working to reset original page query
- Why is my WP_Query outputting my entries twice?
- How to display Related Posts based on number of taxonomy terms matched
- Query & the_content() is showing in the header
- Variable not working in WP_Query
- WordPress notification if new post published
- new WP_query > displays posts only once instead of running through full array
- Related “custom post type” using “custom taxonomy”
- Page that lists publications by classifying them by taxonomy
- How to display grandchildren only of custom post?
- WP_Query based on ‘s’ and tax_queries
- The most recent post of custom taxonomy
- Problems with the WP_Query query for a Custom post type
- How to retrieve taxonomy terms of the current custom post?
- Change display wp post type to wp custom post type
- Query recent posts by author
- WP_query orderby not working after WP4.0 update [closed]
- How do I correctly query posts from a post ID?
- Store custom post type with JSON content
- WordPress custom field sorting, weird behavior: the latest post is at the end
- Default WordPress Query for a Specific Custom Post Type URL
- How can I show a field ID in Elementor with Request Parameter