Skip to content

Instantly share code, notes, and snippets.

<?php
$attachments = new Attachments( 'attachments' ); // 'attachments' is your instance name
if( $attachments->exist() ) : ?>
<?php while( $attachments->get() ) : ?>
Attachments data to go here
<?php endwhile; ?>
<?php endif; ?>
@jchristopher
jchristopher / gist:9667991
Created March 20, 2014 16:31
Use SearchWP's Term Highlight extension to grab an excerpt from anywhere it can (e.g. if no matches are in the actual excerpt, expand the search to string-based Custom Fields)
<?php
/* SearchWP Term Highlight offers an alternative to the_excerpt()
If you're looking to generate any sort of excerpt based on one of the following:
- the actual excerpt
- the generated excerpt from the post content
- the post content itself
- string-based custom field values
this function is for you. It will try to find one of the above (in that order)
and output something with at least one search term in it (if possible)
<?php
// use my_search_engine instead of the default search engine when performing
// Job Listing searches in WP Job Manager
function my_searchwp_wpjmi_job_engine() {
return 'my_search_engine';
}
add_filter( 'searchwp_wpjmi_job_engine', 'my_searchwp_wpjmi_job_engine' );
<?php
// force SearchWP configuration to override WP Job Manager's when performing a Job Listing search
add_filter( 'searchwp_wpjmi_job_post_type_override', '__return_true' );
<?php
// disable SearchWP integration with WP Job Manager Resume searches
add_filter( 'searchwp_wpjmi_hijack_resume_search', '__return_false' );
<?php
// use my_other_search_engine instead of the default search engine when performing
// Resume searches in WP Job Manager
function my_searchwp_wpjmi_resume_engine() {
return 'my_other_search_engine';
}
add_filter( 'searchwp_wpjmi_resume_engine', 'my_searchwp_wpjmi_resume_engine' );
<?php
// force SearchWP configuration to override WP Job Manager's when performing a Job Listing search
add_filter( 'searchwp_wpjmi_resume_post_type_override', '__return_true' );
@jchristopher
jchristopher / gist:9806867
Created March 27, 2014 12:52
Integrate SearchWP and Nexus ElegantTheme
<?php
// This code is ideally added to a child theme's functions.php
// OR
// at the *bottom* of the main theme's functions.php
// (do not forget to remove the opening <?php tag from this gist)
if( is_search() && class_exists( 'SearchWP' ) ) {
// remove the troublesome theme filter
remove_action( 'pre_get_posts', 'et_custom_posts_per_page' );
<?php
if( class_exists( 'SearchWP_Term_Highlight' ) ) {
// instantiate the highlighter
$searchwp_highlighter = new SearchWP_Term_Highlight();
// decipher the search query (NOTE: update the GET var if necessary)
$search_query = '';
if( isset( $_GET['swpquery'] ) && ! empty( $_GET['swpquery'] ) ) {
$search_query = sanitize_text_field( urldecode( $_GET['swpquery'] ) );
@jchristopher
jchristopher / gist:9925992
Created April 2, 2014 00:47
Enable matching any word within a taxonomy term in the Term Archive Priority SearchWP extension
<?php
add_filter( 'searchwp_tax_term_or_logic', '__return_true' );