You need to add setup_postdata($post);
inside your loop:
foreach ( $attachments as $post ) {
setup_postdata($post);
the_title();
the_content();
}
Related Posts:
- How do I set the default admin sort order for a custom post type to a custom column?
- Delete all posts of a custom post type—efficiently
- Create category only for custom post type
- Reducing the use of global $post
- Custom Post Types not showing on Custom Taxonomy archive page
- custom post type or taxonomy
- is_singular() not working if called via callback function of admin-ajax.php
- Taxonomy terms with edit/filter link in wp-admin, in the list of custom posts
- Search everything (posts, pages, tags, cpt, meta)
- Admin to user notices – best practices?
- Reslug a Custom Post Type
- Removing CPT slug from URL results in 404 error for archive page
- Internationalize / translate custom post types & taxonomies
- front end radio custom taxonomy with custom post type
- Search Post Title Only [duplicate]
- Custom post type’s slug gets wrong when adding a custom meta box
- Can’t sort order of wp_query with 2 meta keys
- How to add meta boxes(repeater fields) from WordPress back end?
- Displaying Meta Box Image
- Custom Post Type archive giving 404
- Admin List Dynamic Heading
- Beginner question: Accessing functions.php through admin web interface in order to import custom post types?
- How can i list custom post type categories?
- Query Custom Post by Category
- Custom post type routing with hierarchy
- Role Capabilities: Add New Ones?
- Custom Permalink with Dynamic Taxonomy for Custom Post Type – Works, but breaks other permalinks
- Sub-Sub-Blogs — creating and importing content into a custom sub-type
- Custom post type capabilities require “create_posts” to access the edit posts list page
- Custom post type with slug for plural (archive) and for single
- Custom post type archive not regarding ‘posts_per_page’ => -1
- If post_type is This or This
- Add category in post type dynamically
- Shortcode insertion in tab
- Group custom posts by custom taxonomy names
- Using GraphQL Plugin with Pods Framework
- Use regular category with custom post types
- How to query custom post types posts filtered by multiple custom taxonomies through a form selection
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- Custom Post Type with Templates using Meta Boxes?
- Copy post from category to custum post type
- can’t see custom post content filtered under “mine” filter in admin panel
- Using default WP menu functionality to link to custom post-type listing?
- Custom template Page 2 not working
- Custom post type not showing in search result
- Listing posts under primary and secondary taxonomies
- Removing Custom Permalink Structure for Custom Post Type
- Settings API – save multiple tabs at once
- Set template for custom post type?
- How do I display a list showing custom post types nested within a taxonomy?
- How to create multiple editor?
- make permalink go to a custom single.php file
- Make custom post meta sortable front end
- $wpdb->get_col and ORDER BY?
- get_post_types – exclude multiple post types by name
- Custom post type loop with custom category filtering
- Check if user has comment on current post
- How to show all taxonomies within custom post type loop
- Showing taxonomy terms on custom post type
- Create a page by importing data from an XML file ( On clicking a button inside admin options page)
- get_terms() returns Trying to get property of non-object error for custom taxonomy
- Get admin area editor in frontend
- If meta_value of meta_key is less than today’s date update meta key
- How to list custom post types on a custom post type page?
- Using WP_Query, I want to show posts that are associated with a custom taxonomy term
- Meta box with front-end styling
- Loop and add Specific Categories and Products Images
- Custom Posttype and menu classes
- Is possible register two archive pages for single custom post type?
- Include “Scheduled” (“Future”) Posts in WordPress Post Navigation ( previous_post_link, next_post_link ) for a Specific Custom Post Type
- Custom Post Type with Different Sets of Post Content?
- Add a class to a div if custom post type has specific terms?
- Custom post type paging return home page
- Custom taxonomy returns 404 even with saving permalinks
- Where is get_post_meta value located?
- 2 modal windows with ACF content on Archive page
- Custom post type single page uses the right template in preview mode but shows a different template after being posted
- Custom Post Type works when registered in functions.php but not when registered in plugin
- Custom post type shortcode with taxonomy attribute not working and no errors
- Custom Post Type – Display all, wrap in groups of 3
- Showing Custom Post Type with his templates on a custom page template
- Get name CPT with slug taxonomy
- How to pass modified post to RSS feed?
- Custom post edit page permalink links to edit page rather than the post
- How to mark posts as visited
- Show tags of custom post types in WordPress
- Getting list of Categories for Custom Post Types
- get children from current variable (taxonomy) via shortcode
- Show Templates in Custom Post Type Editor
- Query Pulling the same post twice
- Templates list in “Page Attributes” metabox is inaccurate
- Custom Post Type as invoice or order template
- Pagination in custom loop for custom post type throwing 404 error
- Make each Value of custom field show related posts when clicked
- How can I make a custom post type that loops pages in a new dashboard page, each single page is a new dashboard page (all within the back-end)?
- How can you preserve URLs when moving posts to a custom post type?
- Two blogs on same WP website
- Pagination not working for archive
- Two post types with same single template
- Save post_parent in a custom post type