Plugin Author
TC.K
(@wp_dummy)
Can you shows me all if your codes?
Thread Starter
baga
(@baga)
Here it is:
add_filter('uwpqsf_result_tempt', 'customize_output', '', 4);
function customize_output($results , $arg, $id, $getdata ){
$apiclass = new uwpqsfprocess();
$query = new WP_Query( $arg );
ob_start();
$result = '';
$i = 0;
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
global $post;
$i++;
include 'accommodation-search-results.php';
}
echo $apiclass->ajax_pagination($arg['paged'],$query->max_num_pages, 4, $id, $getdata);
<input type="hidden" name="referrer" value="<?php echo $referrer; ?>">
} else {
echo '<h2>'No results'</h2>';
}
wp_reset_postdata();
$results = ob_get_clean();
return $results;
}
$referrer value is not correct when used inside that function.
Thanks for your help!
Plugin Author
TC.K
(@wp_dummy)
When you use this :
$referrer = get_permalink();
Note that the get_permalink()
need to be in the while loop, or you will need to provide an post ID.
But I don’t know why you want to put it into a hidden input field. It seem it does nothing in the function.
Thread Starter
baga
(@baga)
I tried
$referrer = get_permalink(get_the_ID());
and
$referrer = get_permalink($post->ID);
but none of them seem to work.
The hidden input field is included in a form which sends mail and needs to outup the referrer page permalink, that’s what I’m trying to do (in my previous post I didn’t write the whole form code which is very long, just the hidden input field).
Plugin Author
TC.K
(@wp_dummy)
You need to put the $referrer = get_permalink(get_the_ID());
in the while loop.
while ( $query->have_posts() ) {
}
And you will have the $referrer
in each of the result post.
Thread Starter
baga
(@baga)
It doesn’t work.
It shows the permalink of one filtered post, not the container page which I need.
Plugin Author
TC.K
(@wp_dummy)
You can use the the container page id in the get_permalink(
) then.
Thread Starter
baga
(@baga)
The function is called by many different container pages.
I tried something like:
if (is_page ('first-container')) {
$referrer = get_permalink(1);
}
if (is_page ('second-container')) {
$referrer = get_permalink(2);
}
if (is_page ('third-container')) {
$referrer = get_permalink(3);
}
but still no success.
Plugin Author
TC.K
(@wp_dummy)
Since the it is an Ajax result template, you can’t get the global object like is_page()
.
However, you can try to add a hidden in the search form to indicate which page the form is displayed. And use it later in the result filter.
eg:
add_action('uwpqsf_form_bottom', 'page_identifier');
function page_identifier(){
if (is_page ('first-container')) {
$referrer = get_permalink(1);
}
if (is_page ('second-container')) {
$referrer = get_permalink(2);
}
if (is_page ('third-container')) {
$referrer = get_permalink(3);
}
echo '<input type="hidden" name="referrer" value="'.$referrer.'">';
}
Then in the result filter:
add_filter('uwpqsf_result_tempt', 'customize_output', '', 4);
function customize_output($results , $arg, $id, $getdata ){
$apiclass = new uwpqsfprocess();
$query = new WP_Query( $arg );
ob_start();
$result = '';
$i = 0;
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
global $post;
$i++;
include 'accommodation-search-results.php';
}
echo $apiclass->ajax_pagination($arg['paged'],$query->max_num_pages, 4, $id, $getdata);
//here get the input into your hidden field
<input type="hidden" name="referrer" value="<?php echo $getdata['referrer']; ?>">
} else {
echo '<h2>'No results'</h2>';
}
wp_reset_postdata();
$results = ob_get_clean();
return $results;
}
Note that you can access the input value via $getdata
parameter. It is an array like $_GET or $_POST, so the referrer value would be $getdata['referrer']
Thread Starter
baga
(@baga)
Thanks a lot for your help!
It was enough to add the following code in functions.php:
add_action('uwpqsf_form_bottom', 'page_identifier');
function page_identifier(){
echo '<input type="hidden" name="referrer" value="'.get_permalink().'">';
}
and $getdata[‘referrer’] in my hidden input.
Thanks again.