Skip to content

Instantly share code, notes, and snippets.

@dcooney

dcooney/functions.php

Last active May 22, 2019
Embed
What would you like to do?
SearchWP and Ajax Load More
<?php
/*
Use alm_query_args filter to pass data to SearchWP.
https://connekthq.com/plugins/ajax-load-more/docs/filter-hooks/#alm_query_args
*/
function my_alm_query_args_searchwp($args){
$engine = 'default';
$args = apply_filters('alm_searchwp', $args, $engine);
return $args;
}
add_filter( 'alm_query_args_searchwp', 'my_alm_query_args_searchwp');
<?php
/*
Template Name: Search Results Template
Custom WP search results template. Get value of querystring and pass value to Ajax Load More
*/
get_header();
// http://website.com/search/?term=toronto+canada
$term = (isset($_GET['term'])) ? $_GET['term'] : ''; // get querystring param
?>
<?php
// Add Ajax Load More shortcode with a unique ID parameter.
echo do_shortcode('[ajax_load_more id="searchwp" search="'. $term .'" post_type="any"]');
?>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment