Assuming you are trying to add content only to the first post in the loop, a static variable should do it:
function pietergoosen_insert_content_filter( $content ) {
static $first;
$first = (!isset($first)) ? true : false;
if (true == $first) {
ob_start();
$sidebar = dynamic_sidebar('sidebar-19');
$new_content = ob_get_clean();
if ( ! is_admin() ) {
return pietergoosen_insert_content( $new_content, 2, $content );
}
}
return $content;
}
add_filter('the_content','pietergoosen_insert_content_filter');
Related Posts:
- How to target the default Recent Posts and Recent Comments widgets with pre_get_posts?
- Pass the same object to multiple widgets in a template with one query
- How can i make WP_Query return post image and categories?
- Retrieving list of a custom post type in a widget without using WP_Query?
- How to detect if query is runned from widget?
- Most commented last 24h, week, month, year and all time – posts_where
- Show post number in widget loop
- Error with function in functions.php?
- How to create a widget like this?
- All Posts Have The Same Comments
- How to add a recent post function to a text widget I created for practice?
- Widgets: Show Recent Posts Only if the Posts Have Both Categories X and Y
- How can I show only last year posts in wordpress archive?
- wp_query in form method of widget breaks customizer
- Wp_query to get woocomerce product categorys [closed]
- Pagination when using wp_query?
- Should I use Pre Get Posts or WP_Query
- Is it necessary to use wp_reset_query() in a WP_Query call?
- WordPress retrieving meta data for all custom post types in list view
- how to show posts that are missing a meta_value
- pre_get_posts with get_posts
- Is it true $wpdb->get_results is faster than WP_Query in most cases?
- Is ‘no_found_rows’ a silver bullet for WP_Query optimization when getting all posts of a certain type?
- Why does pagination always break when used on any form of a home page?
- A WP_Query that will look for posts after 2 weeks ago OR with a certain meta value
- Ignore a filter on the media library
- Multiple orderby parameters in pre_get_posts() action
- Select posts wich has no relationship in custom taxonomy
- Multiple keyword search
- Finding the next 5 posts
- WP-PageNavi gives me a 404 when using WP Query
- WP_Query, custom sort and custom filter
- How to wp_query posts with ajax
- post thumb nail
- Filter by title content and meta key at the same time
- Get all remaining posts after a particular post id
- Next/Prev posts on same page
- What is considered a default query for the request filter?
- How to find exact match for search term in WP_Query? What is the additional string added in LIKE query in WP_Query?
- Improve wp query perfomance on large db
- If two first numbers exist in wp_meta_query value
- Two different conditions with a single WP_Query
- How to query for posts without a post_format
- Creating query to show which editor (classic or block) was last used to edit a post/page
- Tax query clause inside a meta query clause?
- Function get_queried_object() return NULL in custom taxonomy
- Search pages that are a child of the current page
- Change query_posts to WP_Query in page but does not work
- Set conditional on template based on referring page slug
- Modify WP Query post__in before have_posts()
- Serve specific “template” page at any URL that ends in its slug
- WordPress search posts by author name with autocomplete
- Meta_query on same meta key, with diffrenct values
- Can we return all category (not post) with Custom Query Filter? [closed]
- WP Query using tax_query & meta_query
- WP_Query – Exclude Posts
- How to control a common terms list from one place?
- Exclude Category filter from Portfolio section
- Search form not working with custom query?
- date_query seems to be ignored by wp_query
- Only display post if published in last 24 hours?
- WP_Query loop else statement not executing
- Modify Search Query if original Query gave no results
- How to cache wp_query with pagination using transients?
- Problem with WP_query
- Why is WP_Query not displaying expected data?
- Filter post query to only show direct children of category
- Get every post with value in meta key
- Display all posts in a custom post type, grouped by a custom taxonomy. How to sort the posts alphabetically and the terms by ID?
- How do I add a relation parameter to my filter query?
- Hacking ‘posts_per_page’ in WP_Query
- How to get posts by category and by choosing a taxonomy term?
- Meta Box WP_Query array for showing items with a certain relationship
- Multi-layered WP_Query
- `offset` WP_Query argument dont work via `pre_get_posts`
- Function the_posts_pagination() not compatible with WP_Query arguments
- Pagination of custom page with custom fields query
- WP_Query custom post with by general tags
- Why are my wp_query args being ignored if post_type = CPT
- WP_Query() not filtering posts for category
- WP_User_Query Orderby Not Working
- WordPress post_status and meta_query
- How to pass a php variable to js within a template?
- Custom query: post__in parameter causes query to be empty
- Custom query return
- Show subscriber id in loop
- WP_Query: Meta_Query with serialized value (or a workaround)
- Query All Attachments and Order by Parent Publish Date
- WP_Query using meta_query with LIKE doesn’t return what it should
- Query post Pagination Problem
- How to organize a WP_Query’s list of posts by category and display category title?
- How to Query Updated Post in WordPress
- Pull Instagram images into an existing loop?
- Query_vars not working for me
- Query posts only shows 1
- Filtering product search results using tags
- how to fetch post_name from WP_Query using Group by a custom value field
- new WP_Query with order args – no more distinction between categories
- How to make OR condition in WP_Query
- query loop “inherit query from template” prevents setting sort order