Skip to content

Instantly share code, notes, and snippets.

Jon Christopher jchristopher

Block or report user

Report or block jchristopher

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:1c0abf666210beed9205
<?php
/**
* The template for displaying search results pages.
*
* @package _s
*/
get_header(); ?>
<div id="primary" class="contents-search-results">
View gist:8695956
<?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 Aug 29, 2015
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…
View gist:8709539
<?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 Feb 5, 2014
Tell SearchWP to explicitly ignore posts both when indexing and searching
View gist:8823890
<?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 Aug 29, 2015
Sample SearchWP Supplemental Search Engine search form
View gist:8905861
<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>
@jchristopher
jchristopher / gist:8923192
Created Feb 10, 2014
Force SearchWP to perform a delta update of a post after it was edited
View gist:8923192
<?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();
}
}
View gist:8922701
<?php
class MyFirstClass {
public function do_math( $x, $y ) {
return $x + $y;
}
}
View gist:9101832
<?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;
View gist:9311560
<?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 Aug 29, 2015
Index filenames for all images in galleries on the current page in SearchWP
View gist:9329543
<?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 ) {
You can’t perform that action at this time.