Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions search-meter.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ function sm_list_popular_searches($before = '', $after = '', $count = 5) {
echo apply_filters('sm_list_popular_searches_display', $display, $searches);
}

function sm_list_popular_searches_shortcode( $atts ) {
$atts_ = shortcode_atts( array(
'before' => '',
'after' => '',
'count' => 5,
), $atts );

ob_start();
sm_list_popular_searches($atts_['before'], $atts_['after'], $atts_['count']);
$ret = ob_get_contents();
ob_end_clean();

return $ret;
}

function sm_list_recent_searches($before = '', $after = '', $count = 5) {
// List the most recent successful searches, ignoring duplicates
global $wpdb;
Expand All @@ -128,6 +143,27 @@ function sm_list_recent_searches($before = '', $after = '', $count = 5) {
}
}

function sm_list_recent_searches_shortcode( $atts ) {
$atts_ = shortcode_atts( array(
'before' => '',
'after' => '',
'count' => 5,
), $atts );

ob_start();
sm_list_recent_searches($atts_['before'], $atts_['after'], $atts_['count']);
$ret = ob_get_contents();
ob_end_clean();

return $ret;
}

function sm_register_shortcodes(){
add_shortcode('sm_list_popular_searches', 'sm_list_popular_searches_shortcode');
add_shortcode('sm_list_recent_searches', 'sm_list_recent_searches_shortcode');
}
add_action( 'init', 'sm_register_shortcodes');

function sm_get_relative_search_url($term) {
// Return the URL for a search term, relative to the home directory.
global $wp_rewrite;
Expand Down