The WP_Post
class has an attribute post_parent
that you can use for this.
while ($q->have_posts()) {
$q->the_post();
$post = get_post();
if (!empty($post->post_parent)) {
// do something different
}
}
Related Posts:
- Where to put my code: plugin or functions.php?
- Display custom post type with shortcode
- WordPress Custom Shortcode Conflicting with Media Library
- Using shortcodes to parse POST request (containing the data from a front-end form)
- How can i list custom post type categories?
- IF statement in a do_shortcode
- Post the content of a specific “Custom Post Type” post within a post using a shortcode
- Strip shortcode from specific post types (formats)
- Pagination in a Shortcode. Get_next_posts_link not working but get_previous_posts_link works fine right next to it
- Why does using WP_Query inside a shortcode in an elementor page cause the arguments for WP_Query to get malformed?
- Generate Shortcodes by Taxonomy
- How would I create a shortcode to display a custom post within a page or regular post?
- Is it possible to create a shortcode that will query a post based on taxonomies?
- WP_Query is printing out only one post when posts_per_page is set to multiple
- Get custom posts with certain ids in a custom loop using a shortcode
- Custom Post Type Loop within Shortcode
- Shortcode insertion in tab
- Shortcode doesn’t display in custom post type
- Add category attribute to custom shortcode
- How to display Custom Post Type Post based on Tag with Shortcode Parameter?
- How to create shortcode to display custom field value on a custom post type
- How to enable shortcodes in a custom post type?
- Get custom fields from a custom post type with a shortcode
- Shortcode for display posts in wp-editor
- Display Recently Added Custom Post Types with Custom Taxonomy Shortcode
- Get custom post type list for every category shortcode
- Using advanced custom fields from one custom post type in another custom post type / using nested shortcodes
- How to render a custom post type template with custom fields using shortcode
- Shortcode for CPT post content in a page
- Next Post links not working in custom post type shortcode
- Can a shortcode included in post content add styles to the ?
- How to retrieve category of a post in have_post loop?
- get_post_meta is not working inside shortcode
- Shortcode leaves no space for other elements?
- How can I add a shortcode to query Custom Post Type with ACF in WordPress?
- Custom shortcode works in Elementor editor but not on frontend
- Get Posts by Category, Tag , and CPT Taxonomy
- post_type internal ID?
- Custom post type Shortcodes wordpress
- Add shortcode inside of the_content()
- WordPress Custom Post Type and Shortcode for Portfolio Items
- Run shortcode in custom script in wp_head if post type is CPT ‘Jobs’
- Creating shortcode id for custom post types
- Shortcode is displaying the content on top of the page [duplicate]
- posts within custom post type all share the same content in the front-end
- Shortcode to return single custom post based on post taxonomy
- Change post type depending on shortcode
- Custom Post Type for Shortcode Use – Prevent it display as a post (with slug)
- Looking to Customize YouTube Video Embeds
- Shortcode / WP_Query in post changes context
- Custom Post Type or Shortcode, What to choose? [closed]
- Modify a plugin function output from another plugin
- Using Custom Post Meta Values in Shortcode
- Why is my custom post query shortcode only showing 1 post?
- display custom portfolio tags
- Content in WP Editor displayed below CPT shortcode [duplicate]
- How do I output a list of a specific post type in a table?
- Shortcode in pages or tempate files for custom post type
- Get Posts List of Current Selected Custom Taxonomy in Shortcode
- php dynamic content inside shortcode
- Alike Shortcode using in Custom Shortcode
- Show in an entry a Custom Post Type associated to a post
- Create a CPT to edit Shortcodes Atts
- Shortcode with loop stacks output
- Custom post type shortcode
- How to display the post using a shortcode in WordPress?
- How can I use javascript in specific posts without relying on a plugin?
- How to generate auto shortcode for custom post type same as Elementor Template?
- From CPT Custom Loop into Shortcode?
- editing shortcode for custom post type within a plugin
- Custom Post type shortcodes
- Custom post type shortcode with taxonomy attribute not working and no errors
- Shortcode and get_template_part
- Load custom post type with ID in a shortcode
- How to seperate posts by categories?
- Display a list of sub-pages of Custom Post Type Parent Page
- Do not parse shortcode in CPT
- Shortcode in excerpt
- Enable shortcodes on custom post type
- Custom meta box in editor of custom post type not working
- Plugin Error on activating
- shortcode order for event custom post type
- Shortcode display CPT Query only showing 1 post?
- Custom Post Type vs Shortcode: Which one is more performant?
- How to call Shortcode categories for custom post types?
- Using get_terms() as shortcode attribute
- adding a shortcode into a custom post type
- Nested loop called with shortcode duplicating the content above the main loop
- Add number in increment of one to DIV ID
- Create shortcode for list of custom post titles with custom fields alongside
- Creating shortcodes with user created forms
- How to Create Short Code Using Custom Post type
- Adding custom shortcode to page leads to page without styling
- custom post types shortode stays on top of other page contents. Is there a bug?
- Shortcode in a page to display custom posts which also have a shortcode in them
- Passing postid of Testimonial Custom Post in Shortcode Parameter
- How to separate posts by categories?
- Problem with shortcode
- strange issue with get_post_type() when using it in a shortcode in text widget
- select categories by ids/display terms only selected