You’re using a raw SQL query to do a post query, this is bad, because:
- There are already APIs that do this
- It is no longer inheriting the default parameters
- It doesn’t go through the caching system so it can be slower
Intead, use WP_Query
.
The reason you’re getting trashed posts is because you’re not specifying what post status you want. By default WP_Query
defaults to published only.
Here is your equivalent post loop:
$query = new WP_Query( array(
'post_type' => 'page',
'post_parent' => $post->ID,
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC'
) );
if ( $query->have_posts() ) {
while( $query->have_posts() ) {
$query->the_post();
// process each post
}
}
Related Posts:
- Advanced Custom Fields – Get custom fields from parent page
- Move from old custom field to new post_thumbnails
- Is there a hook / action that is triggered when adding or removing a post thumbnail?
- How can I migrate all of my custom field thumbnails to the built-in post featured image?
- automatically set “Featured Image” the same as the og:i that is set in a custom field
- Adding a custom field or metabox to the post-thumbnail widget?
- Add url from Custom Field as ‘Featured Image’. Code not working
- Display the contents of a custom field of a page on their child
- Advanced Custom Fields dynamic update_field
- For homepage images (for small business website), is it better to use custom fields or post_thumbnail?
- How to mass update custom fields for more than 20k posts
- how to make nsfw post with thumbanil
- Can I use a Custom Field as the Featured Image URL?
- How to display childrens custom fields?
- Getting the Featured image URL and inserting it as Custom Field on Post update / publish
- User customising position of WordPress Featured Image
- Set featured image from custom field URL
- Custom field as featured image caption
- Is there a way to dump all registered sidebar/widget?
- WP Insert post with post_thumbnail
- Custom field image to Featured Image
- Selectively hiding or allowing thumbnails of featured images on front page
- use custom field value as featured image
- Can you generate a featured image from two images from custom fields?
- Load one page with parent and child pages
- Use a different catalog image than the featured image
- Automatically set the_post_thumbnail to Custom Field Value
- Why is wp_list_pages altering $post->ID of the page?
- Display Child Page with custom fields within Parent Page
- Related post thumbnail not showing up
- Post thumbnail size for custom field only
- How to mark a image attachment as background image?
- Custom field for image, not showing image!
- Show/Hide Featured Image or replace it with custom field [closed]
- Crop custom image size vs actual size
- Importing data for advanced custom fields plugin?
- Gutenberg add a custom metabox to default blocks
- How to rename a custom field?
- Filter post listing by meta value which is a date
- Extra profile field as select box?
- Matching Serialized Arrays with meta_query
- How to activate “custom fields” section in WP3
- Add meta data to the menu
- How to oEmbed from custom field, responsive to container size and responsive
- Copy SEO Meta Desc “Custom Field” to Excerpt field?
- Custom fields won’t display on my blog page
- How to customize default wordpress editor?
- Add an advert every nth Paragraph
- How to edit multiple post with Custom fields
- Undefined index error when saving content on metabox
- Count how many posts have a custom field set
- Update posts after populating ACF field value [closed]
- Display WP-Types custom fields in post [closed]
- how to fetch the meta field keys/meta boxes from a post type?
- Shortcode To Display Post Custom Field Value Inside Excerpt
- Limit the number of acf content when displaying in post loop [closed]
- How do I add an image upload, custom field to a WooCommerce product?
- how to display a widget only on a page where the custom field is defined?
- Show values of custom post meta on ‘Add new post’ page?
- Sort custom post type by multiple custom fields
- display custom field from inner blog in the main homepage of wordpress multisite
- Post selector as Custom Field
- Multiple URLS per post non-ascii
- Display Custom Meta Box Field Only If Value is Present
- Am I overusing custom fields (for adding nearly 5 images and their titles)?
- WP Query – Is this correct?
- How to remove custom fields from the selector?
- What is the proper way to add a required field to a post type? [duplicate]
- How can I combine this php statement to get the results of multiple variable inputs?
- Access ACF fields within custom preview function?
- Looping inside block return
- Scripts and tags will not save or output from my custom meta box
- Sortable Custom Columns not sorting correct
- Is there a size limit to the value you can save in a custom field?
- Using WP Color Picker in Repeatable Fields
- Running wp_postmeta update query does not show the custom fields data in admin section
- How do I save Multiple fields in a meta box?
- How to load script conditionally on custom field in wp_postmeta?
- Can I access Posts of custom-fields via URL?
- Output custom field value
- Best way to achieve multiple links in a post title
- Custom Theme Fields in Settings Menu – apply filters to one of those fields?
- plugin-list-category-post custom fields
- How to display data from custom fields I created?
- Get array of posts based on custom field values
- Add image URL automatically to custom field?
- How to show ACF fields in Gridbuilder custom block
- multiple meta_query and orderby question
- Adding more fields to the registration form
- use mysql to replace one custom field value with another custom field value
- Is it possible in WordPress
- Edit different parts of a page seperately
- I want my post to republish again after adding a custom field
- Custom fields: dropdown values depending on other custom field value
- How do i get a specific user metadata using custom metavalue outside of wordpress?
- Creating an If/Else statement using WPAlchemy MetaBox radio boxs
- How to retrive Custom Fields as Values for a Form field
- Custom fields doesnt work well with any postTAB plugin
- jaredatch metaboxes on video post formats
- Grouped Custom Meta Fields without plugin