Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#97 2022-02-04 18:07:05

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 687
Website Mastodon

Re: glz_custom_fields v2 beta for Textpattern v4.7

Working with glz v2.01 here on txp 4.8.8.

How could i split multiple entries in a multi-select custom field into a list of accessible single entries? I want to use those as search terms, or to order them whatever way possible?.

Example
I have multiple articles of – say – restaurants.
A multi-select custom field called “opening times” contains all days of the week, one per line.

Now what i need to construct is a script, that would let me see only the articles/restaraunts open for instance on Monday.

I can’t seem to be able to do this. I use rah_replace to change the divider between entries just for display, however the results can’t seem to be used as variables or search criteria, as i get no index of what rah_replace found.

How can i approach this? Any hints welcome and thank you in advance!

Last edited by jayrope (2022-02-04 21:51:49)


A hole turned upside down is a dome, when there’s also gravity.

Offline

#98 2022-02-04 18:23:15

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,123
Website GitHub

Re: glz_custom_fields v2 beta for Textpattern v4.7

Can you not use the power of if_custom_field?

<if::custom_field name="opening_times" separator="," match="any" value="monday">
   Hello company that's open on a Monday!
</if::custom_field>

The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#99 2022-02-04 21:49:50

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 687
Website Mastodon

Re: glz_custom_fields v2 beta for Textpattern v4.7

Bloke wrote #332650:

Can you not use the power of if_custom_field?

<if::custom_field name="opening_times" separator="," match="any" value="monday">...

Thanks, Bloke :* Wouldn’t this mean i need seven of those, if i only want to display any possible weekday option on a result page?
Let’s assume, that Monday as well as any other weekday is a clickable word in a list, that leads me to a list of articles, which have been marked like this: How do i get this list at all, in an automated way.

Last edited by jayrope (2022-02-04 21:54:15)


A hole turned upside down is a dome, when there’s also gravity.

Offline

#100 2022-02-05 10:34:06

etc
Developer
Registered: 2010-11-11
Posts: 4,899
Website GitHub

Re: glz_custom_fields v2 beta for Textpattern v4.7

jayrope wrote #332652:

Let’s assume, that Monday as well as any other weekday is a clickable word in a list, that leads me to a list of articles, which have been marked like this: How do i get this list at all, in an automated way.

Not sure for glz_cf, but try accessing

<txp:article match="opening_times" />

via index.php?opening_times=%monday%

Offline

#101 2022-02-05 19:01:46

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 687
Website Mastodon

Re: glz_custom_fields v2 beta for Textpattern v4.7

etc wrote #332656:

Not sure for glz_cf, but try accessing

<txp:article match="opening_times" />...

via index.php?opening_times=%monday%

Thank you, etc. I guess i haven’t explained properly. The first thing i needed to do is to extract each marked single entry from a multi-select glz_cf custom field. If i had those, one by one in an array of all, then i could actually access them for either your or Bloke’s option. I fail to be able to create that array, though…


A hole turned upside down is a dome, when there’s also gravity.

Offline

#102 2022-02-05 19:16:55

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,476
Website

Re: glz_custom_fields v2 beta for Textpattern v4.7

jayrope wrote #332661:

Thank you, etc. I guess i haven’t explained properly. The first thing i needed to do is to extract each marked single entry from a multi-select glz_cf custom field. If i had those, one by one in an array of all, then i could actually access them for either your or Bloke’s option. I fail to be able to create that array, though…

I’ve not tried etc’s suggestion but it sounds like it could work without you having to extract the values.

If I’ve understood it correctly, the % is a wildcard for “some string” (from MySQL LIKE) so looking for a match for %monday% means “match any articles where the value of the matched custom field contains the string ‘monday’ somewhere in it”. So if your custom field values are something like monday|wednesday|friday and saturday|sunday and monday|tuesday|wednesday|thursday|friday, it will output the first and third results.


TXP Builders – finely-crafted code, design and txp

Offline

#103 2022-02-07 09:11:08

etc
Developer
Registered: 2010-11-11
Posts: 4,899
Website GitHub

Re: glz_custom_fields v2 beta for Textpattern v4.7

jayrope wrote #332661:

The first thing i needed to do is to extract each marked single entry from a multi-select glz_cf custom field.

Unfortunately, I don’t remember how glz_cf stores its values, but if you manage to make it output a string like

monday|wednesday|friday

then splitting it is easy. For pre-4.8.8 txp there is a number of plugins (e.g. adi_list, etc_query, rah_repeat, smd_each) that can do it. In 4.8.8 it should work natively:

<txp:custom_field name="opening_times" breakby="|" breakform="timetable" />

where timetable misc-type form could be

<a href="?opening_times=%<+>%"><+></a>

Offline

#104 2022-10-06 07:40:32

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 2,941
Website

Re: glz_custom_fields v2 beta for Textpattern v4.7

A little fwiw, for those who are annoyed by those PHP8.1 warning(s) on the Write tab in debug mode.

Open up the plugin file, and find function glz_clean_default (line 957-963) and update this way (diff):

- return preg_replace($pattern, "$1", $value);
+ return preg_replace($pattern, "$1", (string)$value);

Save the plugin file, access the Write tab and enjoy the calm.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

Board footer

Powered by FluxBB