Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* The template for displaying search results pages.
*
* @package _s
*/
get_header(); ?>
<div id="primary" class="contents-search-results">
<?php
/* Numbered Pagination */
function numbered_page_nav($prelabel = '', $nxtlabel = '', $pages_to_show = 6, $always_show = false) {
global $wp_query, $request, $posts_per_page, $wpdb, $paged;
$custom_range = round($pages_to_show/2);
if (!is_single()) {
if(!is_category()) {
preg_match('#FROM\s(.*)\sORDER BY#siU', $request, $matches);
}
else {
@jchristopher
jchristopher / gist:8709539
Last active August 29, 2015 13:55
When attributing Media search result weight to the post_parent in SearchWP, you may want to automatically append a contextual content snippet from each attached PDF to the original post excerpt. This filter can be used as a baseline for that customization, simply add it to your theme's functions.php and customize however you want. Pay particular…
<?php
function maybe_append_searchwp_pdf_excerpt( $excerpt ) {
global $post;
$pdf_excerpt_length = 15; // number of words in PDF excerpt
if ( is_search() && ! post_password_required() ) {
@jchristopher
jchristopher / gist:8823890
Created February 5, 2014 13:45
Tell SearchWP to explicitly ignore posts both when indexing and searching
<?php
function my_searchwp_prevent_indexing() {
$post_ids = array( 15, 90 ); // EXCLUDE posts 15 and 90 from the index and searches
return $post_ids;
}
add_filter( 'searchwp_prevent_indexing', 'my_searchwp_prevent_indexing' );
@jchristopher
jchristopher / gist:8905861
Last active August 29, 2015 13:56
Sample SearchWP Supplemental Search Engine search form
<div class="search-box">
<form role="search" method="get" class="search-form" action="<?php echo get_permalink( 147 ); ?>">
<label>
<span class="screen-reader-text">Search for:</span>
<input type="search" class="search-field" placeholder="Search …" value="" name="swpquery" title="Search for:">
</label>
<input type="submit" class="search-submit" value="Search">
</form>
</div>
<?php
class MyFirstClass {
public function do_math( $x, $y ) {
return $x + $y;
}
}
@jchristopher
jchristopher / gist:8923192
Created February 10, 2014 20:06
Force SearchWP to perform a delta update of a post after it was edited
<?php
function my_batcache_searchwp_delta_update( $post_id ) {
if ( class_exists( 'SearchWP' ) ) {
if ( $post->post_type != 'revision' && get_post_status( $post_id ) == 'publish' ) {
$searchwp = SearchWP::instance();
$searchwp->purgePost( $post_id );
$searchwp->triggerReindex();
}
}
<?php
/**
* Inject a placeholder in the WP admin menu by bumping everything else down if necessary
*
* @param $position int The desired position to free up
*/
function my_free_up_menu_slot( $position ) {
global $menu;
<?php
function searchwp_include_only_tax_term( $ids, $engine, $terms ) {
// if mycat is the GET variable in use, we want to limit to a specific custom taxonomy term
if( isset( $_GET['mycat'] ) ) {
$my_taxonomy = 'my_taxonomy'; // taxonomy name
$my_term = absint( $_GET['mycat'] ); // taxonomy term as defined by form submission
$args = array( $my_taxonomy => $my_term, 'fields' => 'ids' );
$ids = get_posts( $args );
}
@jchristopher
jchristopher / gist:9329543
Last active August 29, 2015 13:56
Index filenames for all images in galleries on the current page in SearchWP
<?php
function my_searchwp_extra_metadata( $extra_meta, $post_being_indexed ) {
// make sure there's a shortcode
if( has_shortcode( $post_being_indexed->post_content, 'gallery' ) ) {
$galleries = get_post_galleries_images( $post_being_indexed );
if( !empty( $galleries ) ) {
$all_gallery_images = array();
foreach( $galleries as $gallery ) {
foreach( $gallery as $image ) {