Navigation überspringen

[Gelöst] Custom Search / Custom text in stead of empty search Criterium

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:

How to add a value for the search dropdown default item instead of the blank label?

Solution:

Add the Javascript code below to the view:

function setDropdownDefaultValue() {
    jQuery('select[name="wpv-category"] > option:first-child').text('LABEL');
}
jQuery(document).ready(function() {
    setDropdownDefaultValue();
});
 
jQuery(document).ajaxComplete(function() {
    setDropdownDefaultValue();
});

replace LABEL with the label you want to add.

Relevant Documentation:

https://toolset.com/course-lesson/adding-custom-javascript-to-views-templates-and-archives/

This support ticket is created vor 4 years, 3 months. 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.

Dieses Thema enthält 4 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von ronM-3 vor 4 years, 3 months.

Assistiert von: Christopher Amirian.

Author
Artikel
#2327465

Hi,

Custom search by category is used on this page: versteckter Link
By default all news items are shown. The search/filter criterium is empty.

Is it possible to have something like 'All' or 'All news items' instead?

Regards,
Ron

#2328209

Christopher Amirian
Unterstützer

Sprachen: Englisch (English )

Hi there,

Please add the JS code below to the View at the right sidebar:

jQuery(document).ready(function() {
    jQuery('select[name="wpv-category"] > option:first-child').text('All');
});

There you will be able to change the text to All and you are welcome to change it in the code to whatever text that you want.

For more information on how to add Javascript code to a View:

https://toolset.com/course-lesson/adding-custom-javascript-to-views-templates-and-archives/

Thank you.

#2329871

Hi Cristopher,

Thnx. That helped to initially fill a custom text in the search criterium.

However, after filtering on a category and selecting the dropdown again, the custom text has disappeared.
Do you have a solution for that too?

Regards,
Ron

#2329915

Christopher Amirian
Unterstützer

Sprachen: Englisch (English )

Hi there,

Yes, it is possible. Please update the Javascript code to the one below:

function setDropdownDefaultValue() {
	jQuery('select[name="wpv-category"] > option:first-child').text('Alle nieuwsberichten');
}
jQuery(document).ready(function() {
    setDropdownDefaultValue();
});

jQuery(document).ajaxComplete(function() {
	setDropdownDefaultValue();
});

Thank you.

#2329989

My issue is resolved now. Thank you!