Simply use a $_POST
variable to set the terms to the page that handle the recomendations and use an hook into pre_get_posts
to set the query.
I write a function that output the link, and you can use it as a template tag.
Add this function in a plugin or in your functions.php
function more_recomentation_link() {
if ( ! is_single() && ! is_page() ) return;
$post = get_queried_object();
$cats = wp_get_object_terms( $post->ID, 'category', array('fields' => 'ids') );
if ( ! empty($cats) ) {
// I don't know which is the url that handle the recomandation showing
// so I use home_url() change it with rigth url
echo '<form method="post" action='. home_url() . ' id="see-more-form" style="display:none">';
foreach ( $cats as $cat ) {
echo '<input type="hidden" name="cats[]" value="' . $cat. '" />';
}
echo '</form>';
}
echo "<a href="https://wordpress.stackexchange.com/questions/113415/javascript:void(0)" onclick='document.getElementById(\"see-more-form\").submit();return false;'>" . __('See More') . "</a>";
}
function set_recomendations_query( $query ) {
if ( ! is_admin() && is_main_query() && isset($_POST['cats']) && ! empty($_POST['cats']) ) {
$tax_query = array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $_POST['cats']
);
$query->set('tax_query', array($tax_query));
$query->set('posts_per_page', -1);
}
}
add_action('pre_get_posts', 'set_recomendations_query');
The in the template, even in sidebar, show the ‘See More’ link simply using
<p><?php more_recomentation_link(); ?></p>