Skip Navigation

[Resolved] WordPress custom search with Toolset BIS

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

Problem:
How to filter view by custom field

Solution:
You should try to add custom field filter from your view's Filter section by clicking on "New Filter" button.

you can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/wordpress-custom-search-with-toolset-bis/#post-627405

Relevant Documentation:
=> https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/

This support ticket is created 6 years, 9 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 14 replies, has 2 voices.

Last updated by bouchairY 6 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#626430

Hello
As i explained in my last ticket :

here is the problem :

I have a view wich list some offers and each offer has some files (pdf, doc ...) attached to it (via ACF Pro)
I want to make a custom search by words in files title and display correspondant offers

The files are related to offers via a repeater field wich is difficult to search

Workaround :
Create text metafileds attached to offers and after each uploading files, copying some infos to theses metafields

My first problem :

Each time, il upload a file, it will be renamed manually to :

offername_doctype_object_validitydate_startdate_enddate.extension (pdf or doc)

I will create a search view and try to serach by :

object
validitydate
startdate
enddate

how can i extract each word separetd by _ (underscore) ?

Thank you

#626908

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - you can separate the word using PHP function explode():

More info:
=> hidden link

However - I do not see a way to search using the custom fields and that will apply on same filename. There is no way until you chose custom approach to do this and I mentioned this in previous ticket as well.

However I would like to know - how you will add the search fields?
object
validitydate
startdate
enddate

As a text box or dropdown?

Also, in which format the start and end date will be displayed?

#626988

Hello

Here is the idea :

I will converting an ACF repeater sub field to standard WP meta

Please sread this article for more informations :
hidden link

Normally :

object will be added as dropdown
validitydate, startdate, enddate as date fields

Is it possible or not ?

Thank you

#627126
metawp.jpg
metawp1.jpg
metawp2.jpg

Hello

For the moment (i will not rename title) but use metafields attached to each file as you can see in metawp1.jpg

We will take as example : the "Validity date" metafiled wich contains :
"31/03/2018" for the first file and "23/03/2018" for the second file

In other hand, i have created a simple metafield called "Validite_wp" (please see metawp2.jpg)
After applying code in that article : hidden link

We can see (metawp.jpg) that the new simple metafield contains : "31/03/2018" and "23/03/2018"

NOW, we can filter using Views and this simple metafield ?

Thank you

#627199

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - First of all, Types date field uses the Unix timestamp to store the date value. You need to convert the date field string value to unix timestamp.

#627282
timestampdb.jpg
timestamp_cpt.jpg

Hello
I converted date to unis time stamp, for "31/03/2018" i have : "1522454400" wich is stored in the simple metafield
It is interesting as mentionned in the precedent article, to create the simple metafields as just db fields not as ACF fields to not be displayed when editing the post.
How can I add a metafield without using Types or ACF plugin ?
Thank you

#627288

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - as described before - you can use native wordpress function add_post_meta and update_post_meta.

More info:
= https://codex.wordpress.org/Function_Reference/add_post_meta

However - with the screenshot you shared I see that there is multiple entries available for single metakey for single post ID. It looks like its repeating field.

#627316

Hello
All metafields are correctly filled now

I want to create a View with search features to have :

List all offers CPT that have a Validity date ( "validite_wp" metafield ) bigger than a given date
How can I do it ?

Thank you

#627318

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - as normally - you should try to add custom field filter.

but I would like to know how you will pass the given date?

More info:
=> https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/

#627323
search_typedoc_wp.jpg

Before searching by date, i try to serach by "typedoc_wp" wich will have only 7 values :

Contrat
Offre
Factsheet
Add contrat
Tarif
Info
CGV

I add a search view, but when i search, it returns all posts

Thank you for your help

#627325

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Please share problem URL where you added the view and access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#627405

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please check now.

You have added the filter outside the [wpv-filter-controls] shortcode. I've added the filter within it as given under:

[wpv-filter-start hide="false"]
[wpv-filter-controls]

<div class="form-group">
	<label>[wpml-string context="wpv-views"]typedoc_wp[/wpml-string]</label>
	[wpv-control-postmeta field="typedoc_wp" type="select" url_param="wpv-typedoc_wp"]
</div>

[wpv-filter-submit output="bootstrap"]
[wpv-filter-reset output="bootstrap"]
[/wpv-filter-controls]
[wpv-filter-end]

I can see its working now. Could you please confirm

#627410

Hello
Thank you it works
Now if i want to filter by "validite_wp" date

Display all offers that have "validite_wp" bigger than a given date
The given date is set via a calendar field

How can I do it ?

Thank you

#627412

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You should chose the same way - try to add filter but I dont think that calendar filter will be available for you as you are using postmeta filed.

You need to find a way how you can add calendar as filter.

For all - the same method should apply:
=> https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/

Also, as your original issue is resolved. please kindly open a new ticket for your each new question. This will help other users searching on the forum. Thank you for the understanding.

#627508

Thank you