Here’s your updated shortcode function which puts output in a variable and returns it. Note that you have to use functions that return data rather than output directly, in this case get_the_post_thumbnail()
is used in place of the_post_thumbnail()
function cor_etalage_add_shortcode() {
$output="<div id="etalage"><ul>";
$the_query = new WP_Query(array(
'post_type' => array(
'portfolio'
)
));
while ($the_query->have_posts()) : $the_query->the_post();
$output .= '<li>'. get_the_post_thumbnail($post->ID,'etalage') .'</li>';
endwhile;
wp_reset_postdata();
$output .= '</ul></div>';
return $output;
}
add_shortcode('etalage', 'cor_etalage_add_shortcode');
EDIT oops, forgot to pass the post ID with get_the_post_thumbnail
, updated.
Related Posts:
- How to dynamically attach pictures to a carousel
- Two custom post types divided in two columns inside a bootstrap carousel
- Custom Post type content within a slider
- Display the current post in browser as the first post in a loop (for a slideshow)
- Slider from custom post type
- Is image slider possible in wordpress post
- Grid slider with custom post type (how to filter with taxonomies?)
- Why is my custom post type slider only displaying the latest slide?
- How do I get the permalink of a custom post type?
- Row actions for custom post types?
- How to set parent-child relationship between differents custom post types
- Add Custom Fields to Custom Post Type RSS
- Do I need a nonce field for every meta box I add to my custom post type admin?
- Add content in custom post type page after the title and before columns
- get attachments for all posts of particular post type
- Check if a custom taxonomy archive page is being displayed
- Count posts or custom post types from last 24 hours (or from today)
- title_save_pre on post publish
- How to add a post from a custom post type as the static page?
- Priority for Categories, Tags, Taxonomies, Posts, Pages and Custom Posts with same url
- Using Custom Meta Capabilities on Custom Post Type
- Separating Search Results By Post Type
- Assigning a role to a specific custom post type (and ignoring other post types)
- How can I programmatically save data into custom fields that contain serialized data?
- Displaying custom post type on front page
- Custom Post Types: Custom columns with Title submenu?
- Custom Role can’t trash Custom Post Type
- Remove “Get Shortlink” button in admin of custom post type
- register multiple post types on one menu entry
- current-menu-item class for custom post type parent
- Changing sort order with pre_get_posts using is_post_type_archive doesn’t change category pages
- how to add extra GET parameters to post to url with add_rewrite_rule?
- How to use the Display Name as the post title in a custom post type?
- Removing parent slug in hierachial custom post type
- Open Custom Post Type as PDF
- get_posts() with custom post type does not work outside page.php
- CPT + CMB2: data not displaying for only first post in loop
- Remove edit or add facility for custom post type
- Why doesn’t a custom post type permalink ever hit index.php
- Set a maxlength for the title input in a custom post type
- How to get categories linked in posts for a specific post type
- WP Rest API – How to get an empty response if query has no posts
- Get general taxonomy name for a Custom Post Type
- Cross reference custom post types
- Allow user to only access custom post type
- Filtering posts list table
- Order post by date with ACF
- Template not working for the custom Post type
- custom post type template
- Loop increase number
- delete_post_meta() for whole CPT / multiple posts?
- Move Genesis Single Page/Single Post Title
- Custom filter for main search: how to exclude specific post_type from search results
- Is This Code Efficient – Or is there a better way?
- display custom taxonomies limited to custom post type?
- Category Search / Custom Post Type search on my website. Custom Post Types that are “page-like”?
- List Custom Post Types in Admin Dashboard
- CPT Archive pre_get_posts not working?
- How do I show a link or ‘Read More’ button on a custom field excerpt when it is less than the word limit
- wp_editor for custom post type doesn’t save value
- Hide text if query has no posts
- Am I mixing up the concept of posts pages and categories?
- Writing a custom Glossary plugin
- How to achieve a multi-taxomony layout with posts?
- How to show Custom Post Types under Taxonomy in a new WordPress page template?
- Displaying all posts by category and showing content on click
- Custom post type and custom taxonomy key lenght & query performance
- Feature image Gallery made from Custom Post type + Categories
- Custom post type in slider front page Breaking layout
- register_rest_field update_callback don’t work for $_FILES
- Getting data from dynamically allocated metaboxes within a custom post
- Filter custom WP_Query by first letter of a custom field – hopefully using Search and Filter Pro?
- Custom permalink with custom taxonomies for custom post type
- Meta query broken since 4.7.4 Update
- Custom post type , page template not grabbing the page template
- Can I organise my custom post types by page?
- Problem to get the link of the default ‘post’ post type like the orther custom types
- Best Plugins for Complex Index of Resources [closed]
- How Can a CPT in WordPress have a page 2 without an error?
- Get the custom post type slug but remove the rewrite prefix?
- Remove sequential number from permalinks
- custom post type archive slug vs. custom page template
- WordPress loop for multiple custom post types
- Custom Post Types in plugins?
- how to add pagination and post query in taxonomy-taxonomy-term.php? [duplicate]
- Pagination not working with custom loop
- How to bring custom meta boxes to custom post types?
- Custom role, capabilities, and post type: preview button wrecks things
- Most efficient way of deleting post
- Problem with menu categories doubling up when updating database?
- Noob Loop Question
- Custom Post Type fields not showing in dashboard
- Switched server & domain name, now custom post types won’t save
- Display one post based on ID from $_GET
- Display associated taxonomy child name on single CPT page
- Custom Post Type to Plugin
- How to query posts by category with the_title();
- Get images only from a certain post type
- WordPress custom field sorting, weird behavior: the latest post is at the end
- Custom slugs with dates & IDs on Custom Post Type