WordPress Functions.php add_filter after comment redirect
Thursday, March 15th, 2012add_filter(‘comment_post_redirect‘, ‘redirect_after_comment‘);
function redirect_after_comment()
{
wp_redirect($_SERVER['HTTP_REFERER']);
}
add_filter(‘comment_post_redirect‘, ‘redirect_after_comment‘);
function redirect_after_comment()
{
wp_redirect($_SERVER['HTTP_REFERER']);
}
We have many installations where I work, some of them newer, some older, some severely whacked at by coders, some pretty much default installations.
Anyhow, now they want a page from which a visitor could enter a search term, click submit, and get results from all of the separate applications!
Here is my solution:
The new page has your basic self submitting form:
<form action=”" method=”post”>
<label for=”search”>Search:</label>
<input name=”s” type=”text” value=”" />
<input type=”submit” />
</form>
Then, of course, it grabs what has been submitted:
<?php
/**
* Get Search parameters
*/
$search = $_POST['s'];
$search = str_replace(” “,”%20″,$search);
echo $search;
?>
This checks to ensure that the user didn’t submit nothing (as WordPress would give us every post as currently coded…! ick). This would also be a great place to guard against injection attacks (or in the last step of course), to filter what may be searched for, etc., but I’ll leave those concerns for another discussion:
<?php
/**
* If desired search is NOT empty, search, otherwise don’t
*/
if(($search != ”) && ($search != null) && (!empty($search)) )
{
?>
Now we curl in the results from each installation:
<?php
/**
* Get Search results from WP app 1
*/
$sub_req_url = “http://YOURAPP1URLHERE/searchpage.php?s=” . $search;
$ch = curl_init($sub_req_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$podcast_return = curl_exec($ch);
curl_close($ch);
echo $podcast_return;
/**
* End
*/
?>
<?php
/**
* Get Search results from WP app 2
*/
$sub_req_url = “http://YOURAPP2URLHERE/searchpage.php?s=” . $search;
$ch = curl_init($sub_req_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$podcast_return = curl_exec($ch);
curl_close($ch);
echo $podcast_return;
/**
* End
*/
?>
Now let’s close our IF block, and maybe provide ELSE if we want to…
<?php
/**
* close if empty block
*/
}
else
{
}
?>
Ok, that’s the end of our new page, again, I’ll leave formatting of the results and the rest of the page to another discussion. Now let’s make the above mentioned search pages “searchpage.php” (make one for EACH APP, lives in the ROOT of EACH WP installation that we’re searching!):
<?php
/**
* WordPress App 1 Post Results Pull-In
*/
define(‘WP_USE_THEMES‘, true);
include(‘wp-load.php’ );
$query = new WP_Query(‘s=’ . $_GET['s']);
if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
/* Again, how you choose to skin the results could be implemented here, but I’ll leave that up to you… */
<div id=”post-<?php the_ID(); ?>“>
<h2><?php the_title(); ?></h2>
<div>
<?php the_content(‘<p>Read the rest of this page »</p>‘); ?>
<?php wp_link_pages(array(‘before’ => ‘<p><strong>Pages:</strong> ‘, ‘after’ => ‘</p>‘, ‘next_or_number’ => ‘number’)); ?>
</div>
</div>
<?php endwhile; endif; ?>
Whoohoo! Great Work!
so that anchor tags always nicely point to your application root use:
get_bloginfo('url')
go to your theme’s function script:
wp-content/themes/yourthemename/function.php
at the top insert the following (add to ‘<img>’ below to NOT strip out other specific tags, or simply comment the line out…):
function improved_trim_excerpt($text) {
global $post;
if ( ” == $text ) {
$text = get_the_content(”);
$text = apply_filters(‘the_content’, $text);
$text = str_replace(‘]]>’, ‘]]>’, $text);
$text = strip_tags($text, ‘<img>’);
$excerpt_length = 55;
$words = explode(‘ ‘, $text, $excerpt_length + 1);
if (count($words)> $excerpt_length) {
array_pop($words);
array_push($words, ‘[...]‘);
$text = implode(‘ ‘, $words);
}
}
return $text;
}
remove_filter(‘get_the_excerpt’,'wp_trim_excerpt’);
add_filter(‘get_the_excerpt’,'improved_trim_excerpt’);
some references: http://codex.wordpress.org/Function_Reference/the_excerpt, http://www.aaronrussell.co.uk/blog/improving-wordpress-the_excerpt/
If you found this post, you think you’re stuck with Podpress, and/or you’re wanting to make your podcast viewable on mobile devices. I was in the same boat until just recently, stuck with a podcast I’d initially setup with Podpress years ago, support for which has been worryingly spotty and dwindling, wishing I could now ditch Podpress, but I had over 160 posts I didn’t want to convert….
What I didn’t realize is that the creators of Powerpress had exactly that in mind when they developed Powerpress! All I had to do was install Powerpress, activate it, ensure that it’s settings were correct, and then deactivate Podpress, and bam, it worked. SO AWESOME, highly recommended.
So I can successfully declare today, that I’ve migrated now 3 podcasts from Podpress to Powerpress, one with 84 posts, one with 164, another with 11.