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]
- Find out total number of pages in global query on archive page?
- Resetting post data to previous loop in nested loops
- Order by multiple meta key and meta value [closed]
- Order by optional meta key?
- WP_query to get the first two latest posts, then another loop to get the next three
- Why is WP_Query not working with category_name?
- ‘Trying to get property of non-object’ when using WP_Query with ‘fields’ => ‘ids’
- Displaying several specific pages using WP_Query()
- Query to return maximum of one post per author
- Get attachment by slug
- RSS feed with specific keyword
- Get All IDs Of A Post Type Using WP_Query
- Group posts by custom field
- Multiple endpoints in one URL
- How to get the posts published in last two days using WP_Query?
- getting posts and number by specific meta value in multiple meta
- How to query using a combination of custom_field values?
- Get attached media only
- how to fire join query with post_meta
- Show one post per author and limit query to 8 posts
- Get term by custom term meta and taxonomy
- SELECT * FROM $wpdb->posts WHERE ID > 160
- How to show the posts of some category first, and then all other
- Pagination problem after WP_Query with tag filtering
- Custom Loop in Page Admin Causing Other Fields to Fail
- Pagination stops at page 6
- How to limit total number of posts in wp query loop?
- How to get posts on a specific date – WP Query
- WP_Query with Metavalue
- My Main Query Modification is Messing up my dynamic main – why?
- Using Ajax to load more posts | Help me change the wording on my button to notify the user
- Get a post from other loop each n-posts in the main loop
- Search for multiple tags?
- WP_Query() and get_posts() can’t handle over a thousand posts?
- Sort by price woocommerce by ID post_meta
- Which is faster wpdb & get_row or wp_query & ge_post_meta?
- Why is WP_Query not displaying expected data?
- Customy WP Query Args are convertet in SQL result
- Filter post query to only show direct children of category
- Highlight current post title on a page
- Why won’t draft listings appear for non-admins?
- My WP_Query didn’t work after upgrading to WordPress 3.2
- meta queries do ‘either/or’ checks
- search serialised meta_value for date value?
- has_excerpt() not working inside wp_query
- Apply query arguments after the nth post
- How to properly use AND / OR in custom search
- Get post and its children with WP_Query
- Using get_posts to get posts based on a checkbox value with Advanced Custom Fields
- Searching by title, content and custom taxonomy
- Storing an array of objects related to each user
- Paging + WP Query
- Getting the permalink to the latest post from a category
- How to restrict search on a certain page to only return results against custom taxonomies?
- filter posts by meta key with pagination
- Ajax (jquery) wp_query pagination returns -1
- Query to get result by Title or Meta along with tax_query parameter
- Oxygen Repeater Advanced Query
- Use dedicated functions
- Woocommerce Get Orders By Meta Value
- Pagination not working on archive.php template?
- Save large WP_Query to transient === false
- WordPress Query optimaization for slow query
- WordPress – just refresh blog archive by new query
- how to move a page from one drop down menu to another drop down menu
- WP_Term_Query->get_terms() very slow query for WordPress filter
- Meta query doesn’t remove placeholder escape before query
- Multiple values in WP_Query : category__and
- Get all wp_users sort by metakey
- How to use wp_query in different column in single loop
- Paginated Post List on Front Page
- modifying the loop multiple times with arguments passed through ajax to wp_query
- WP_Query – show posts where meta value and user_email match
- WP_Query causing links to not work
- Website goes slow down after importing long database
- Pagination for custom query throws 404 errors on last pages [duplicate]
- Order posts by custom column using pre_get_posts
- wordpress nested loop
- Need help setting up a search form for wordpress [duplicate]
- Including ‘cat’ => $cat breaks meta_query
- Query posts only shows 1
- First post outside of loop, homepage only?
- How to retrieve _embed (etc) fields in get_posts custom query?
- Using ‘meta_query’ with the ‘pre_get_posts()’ hook disables searching for post titles
- How to save the results of a query as a php file for an autocomplete search bar