Skip Navigation

[Resolved] Adding search options as titles

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to display what was being search for on the results page example "Search Results for : ...."
Solution:

This can be done by using the shortcode below.
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-search-term

This support ticket is created 5 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 17 replies, has 2 voices.

Last updated by leilaG 5 years, 4 months ago.

Assisted by: Shane.

Author
Posts
#1294009

Is it possible to display the titles of search options above a table of results?

For Example:

Search and filter options were:

Locations
Location 1
Location 2
Location 3

Buildings
Building 1
Building 2
Building 3

If the user selected Location 2 and Building 3

Is there a way to display those 2 as a title above the table of results?

#1294139

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Leila,

Thank you for contacting our support forum.

What do you mean the titles of search ? Are you referring to what the user had searched for ?

Please let me know.

Thanks,
Shane

#1295843

Yes what the user has searched for.

#1296247

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Leila

The only way to do this is by having the text search bar on your parametric searches.

It's not possible to have a dropdown search bar for this.

Thanks
Shane

#1296383
toolset-title.jpg

For example see attached.

User has selected the date 27/07/2019 and Building: Laurus

Is it possible to have these 2 displayed above the table of results (see red circled area)

#1296407

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Leila,

Yes this is possible and you can do it with this shortcode here.
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-search-term

Please let me know if this helps.
Thanks,
Shane

#1296463
date-numbers.jpg

Thanks that worked, but the date is displaying raw numbers (see attached)

I added a date format but that didn't work.

<h3>[wpv-search-term param="wpv-wpcf-target-date" format="Y-m-d"]
[wpv-search-term param="wpv-wpcf-building-access-required"]</h3>

#1297753

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Leila,

So for the date field it gives a timestamp, the format="Y-m-d" attribute won't work here as its not a valid attribute of this shortcode.

I've created a custom shortcode to help you format this.

// Add Shortcode
function wp_convert_timestamp( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'timestamp' => '',
			'format' => '',
		),
		$atts
	);

	$date = date($atts['format'], $atts['timestamp']);
	
	return $date;

}
add_shortcode( 'wp_convert_timestamp', 'wp_convert_timestamp' );

Add this to your toolset custom shortcode in Toolset -> Settings -> Custom Code and ensure that its activated.

The usage in your case would be.
[wp_convert_timestamp timestamp="[wpv-search-term param='wpv-wpcf-target-date']" format="Y-m-d"]

Thanks,
Shane

#1297895
visitor-timestamp .jpg

Hey! I followed the instructions, but it's displaying the shortcode and the date, have I missed something?

#1297919

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Leila,

Did you click the activation button on the custom code when you added it to the toolset custom code section ?

#1297923

Opps no it wasn't active, but now it's showing

Warning: date() expects parameter 2 to be integer, string given in /nas/content/live/biocityhq/wp-content/toolset-customizations/wp_convert_timestamp.php on line 22

#1298075

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Leila,

So i suspect that happens when there isn't any parameter.

Try it like this.


// Add Shortcode
function wp_convert_timestamp( $atts ) {
 
    // Attributes
    $atts = shortcode_atts(
        array(
            'timestamp' => '',
            'format' => '',
        ),
        $atts
    );
  $date="";
  if(!empty($atts['timestamp'])){
    $date = date($atts['format'], $atts['timestamp']);
     }
     
    return $date;
 
}
add_shortcode( 'wp_convert_timestamp', 'wp_convert_timestamp' );


This should fix your issue now.

Thanks,
Shane

#1298331

Add the code, still the same.

Do I need to update the code in views or does that still remain as

[wp_convert_timestamp timestamp="[wpv-search-term param='wpv-wpcf-target-date']" format="Y-m-d"]

#1298639

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Leila,

You shouldn't need to make any changes on the frontend.

Would you mind allowing me to have admin access to the site so that I can have a look at what is happening here for you ?

Thanks,
Shane

#1299605

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Leila,

The code should be working now.

The problem was that it was not copied correctly and had a bunch of special characters in it.

Thanks,
Shane