Use buffer to simply do that with ob_start()
& ob_get_clean()
.
function custom_summary($atts) {
extract(shortcode_atts(array(
"category" => "",
"posts" => ""
), $atts));
ob_start();
$my_query = new WP_Query("category_name=$category&posts_per_page=$posts");
while ($my_query->have_posts()) : $my_query->the_post();
// Do all the things.
endwhile;
wp_reset_postdata();
return ob_get_clean();
}
add_shortcode('summary', 'custom_summary');
Related Posts:
- Split Content and Gallery
- Loop after page content
- Split Content and Gallery
- Making a specific page wordpress compatable that is not index
- How can i display the content in plaintext
- remove tags from the_content
- How to return loop contents
- Using the Loop to show all levels of subpages under a parent page? Halfway there
- Child Pages Loop
- Get post by page name or slug
- Loop that displays PARENT PAGE & CHILD PAGE & outputs GRANDCHILD PAGE title and content
- the_content and wp_link_pages
- How do I get the attributes of a short code from a post?
- Display subpages under parent page as a list within a loop
- Is including the loop necessary for page.php? [duplicate]
- Add Incrementing ID to each paragraph in the_content
- Return vs Echo Shortcode
- Identify the page being shown while in The Loop
- Use the_content outside the loop
- as a shortcode within the loop?
- get_the_content not working in loop?
- If Loop has odd number of posts on last page Custom style for last post in it
- Function to show only first instance of shortcode
- the_excerpt(), get_the_excerpt() and the_content() all killing “the Loop”
- Content/Excerpt length control for a specific loop?
- single page site with subpages
- How to loop through ALL pages?
- Combining the_excerpt with the_content
- Adding shortcode closing tag after a loop
- the_content() seems to block my ACF-code
- What are the disadvantages of using global variable?
- Removing the_content() from the page
- Loop and Page template : my WP_query don’t take args
- How to make post content from each post display within the same div
- Create a loop that gets pages with their template
- Display content of page template (get_page)
- wp alchemy multiple image uploader output images to template
- Only display videos and images in the_content() within loop
- Displaying terms based on loop posts?
- Missing image in gallery shortcode in custom feed
- Shortcode with a foreach and arguments
- Styling text and images in the_content()
- Output loop leveraged shortcode twice on one page
- Get Page content to displayin Bootstrap Modal
- Custom Loop Using Shortcode in Custom Page Template
- Shortcode in posts called by ajax is not working
- How do I make a variable available inside partials?
- Cannot retieve the_content() and the_author() – both returning empty strings
- Exclude page name from loop
- Stepping through a foreach loop – adding +1 to the end of it so next time it loops it starts on item 2
- Include multiple page ids in loop
- Trying to get property of non-object in shortocde
- Get post offset/posts page offset in single post page (outside the loop)
- First archive page with a few posts
- Tags on page (not post) returns nothing – why? Improved clarified question!
- WordPress shortcode in content, output in sidebar?
- Query posts only with actual text content (not including shortcode or images)
- Exclude page from loop results
- How is WordPress changing the content markup?
- Display specific page (that is child) content on parent page
- Get post content from outside the loop with plugin shortcode usability
- How to put a block of code between [shortcode][/shortcode] in do_shortcode()?
- Print the whole page?
- WP_Query is only looping home page, not pages
- How do i create a list-posts-page?
- WordPress: query pages except remove one page
- How can I pass additional params to a shortcode while in a loop?
- Get a Post Loop based on Logged in User information into a Shortcode
- How to add pagination in Terms
- Insert content above an embedded video inside Wordress’ php the_content
- Archive: Lists itself
- is it bad to copy the loop for a template?
- pages shortcode filtering by category
- Get top Page IDs from menu and cycle through their child pages on a scroller
- Shortcode for pulling specific Post Title outside loop when ID is passed in
- Search – Check if post is a page on search page
- the_content() keeps repeating itself
- Echo Most Recent Sticky Post in Loop?
- Structure and Display Content from Multiple Pages on Single Page
- Default Template infinite loop of Title
- how to use custom loop in the_content filter
- change the_content images for different sizes (Desktop, tablet, mobile)?
- get_template_part() to render single page Theme
- Using shortcode within shortcode with dynamic variable
- In Loop Output Place Custom Field Content In Between Paragraphs
- Help with add_filter(‘the_content’, ‘some_function’) and multiple matches
- How wp maps urls into files
- Single Loop With Dual Content Area
- get_page() unlike Loop returns the post content without html tags. How can I fix this?
- How to add custom HTML markup and classes to the_content()?
- the_content() “crashes” for single pages
- Creating mixture of shortcodes to use in the visual/text editor
- Hide old posts each year
- Is it possible to display previous post revision?
- Duplicated posts on category page
- WordPress loop: exclude if it is the latest post
- Enabling users to control custom loop’s query
- Wrap every four posts within a div [duplicate]
- numberposts not responding to wp_reset_postdata()
- Building theme so user can change header image [closed]