How to loop for every result found in the_content() when using the search query?

got a solution with https://stackoverflow.com/questions/15737408/php-find-all-occurrences-of-a-substring-in-a-string $lastPos = 0; $positions = array(); if($pos==”){} else{ while (($lastPos = strpos($content, $findme, $lastPos))!== false){ $positions[] = $lastPos; $lastPos = $lastPos + strlen($findme); } // Displays foreach ($positions as $eachPos){ $pos = $eachPos; $exctractAfterQuery = substr($content,($pos+strlen($findme) ),40); $exctractBeforeQuery = substr($content,$pos-40,40); $newContent .= “[…”.$exctractBeforeQuery.'<strong class=”search-highlight”>’.$findme.”</strong>”.$exctractAfterQuery.”…]<br>”; } } It works well and … Read more

Can somebody tell me how I am supposed to be using blogs.dir for network / MU sites?

blogs.dir was the way to handle specific blog plugins and themes when it was WordPress-MU but since version 3 came out and the WordPress-MU was integrated into WordPress Core and introduced WordPress Multisite, that’s no longer the story. WordPress Handles the creation of the new blogs/sites in the database and mainly in the background so … Read more

Get the content inside shortcode and apply external function to it?

The following adds the shortcode [my_t_shortcode], which accepts an attribute ‘lang’, and applys the above mentioned function to the content. //Add shortcodes add_shortcode( ‘my_t_shortcode’, ‘wpse41477_shortcode_handler’ ); //It’s good practise to make sure your functions are prefixed by something unique function wpse41477_shortcode_handler( $atts, $content = null ) { //This will extract ‘lang’ attribute as $lang. You … Read more

Display content of page template (get_page)

You seem to be confusing the database object that is a post/page, and the rendered output that is a post/page. The data contained in the wp_posts and wp_post_meta tables define the post object. A template file defines the rendered output when a given database object is queried. There are three types of queries: the default, … Read more

apply_filters(‘the_content’) – make it ignore shortcodes?

The function that parses the shortcode, do_shortcode is added as a filter on the_content by default, at priority 11. You can remove it using remove_filter: remove_filter( ‘the_content’, ‘do_shortcode’, 11 ); Call this right before you’re actually using the_content, and add it afterwards (in the unlikely case that it’s needed after that): remove_filter( ‘the_content’, ‘do_shortcode’, 11 … Read more

Set post title based on first h2 element in the content section

If you can handle this in the PHP side, you might be able to pull the h2 tags from the content using regular expression. PHP VERSION Test content $content = “<h2>This is H2 Content</h2><p>This is p content</p>Random Content<h2>This is another H2 section</h2><b><h2>This the third H2 section</h2></b>”; Grab any text inside H2s preg_match_all(‘#<h2>(.*?)</h2>#’, $content, $matches); // … Read more