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,468
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: 5,240
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,743
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: 5,240
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: 3,227
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

#105 2024-02-17 19:02:13

amordecosmos
Plugin Author
From: London (Hometown: Vancouver)
Registered: 2004-08-03
Posts: 114
Website

Re: glz_custom_fields v2 beta for Textpattern v4.7

Is there a way to extract the pre-entered values of select/multi-select or checkbox/radio button?

For example, say my values for custom_field ‘genre’ were:

Sci-Fi
Romance
Thriller
Pre-Code

is there a way to pull them out and display on a public page?*

For example:

<select>
<option>Sci-Fi</option>
<option>Romance</option>
<option>Thriller</option>
<option>Pre-Code</option>
</select>

I’d like my user to be able to update in the Extentions->Custom Fields and not have to go edit a webpage afterwards.

  • Without resorting to some <txp:php> database coding

Offline

#106 2024-02-17 21:26:20

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

Re: glz_custom_fields v2 beta for Textpattern v4.7

amordecosmos wrote #336693:

Is there a way to extract the pre-entered values of select/multi-select or checkbox/radio button … and display on a public page … without resorting to some <txp:php> database coding?

Not currently. There is a non-public function in the plugin but it requires more input values. If you’re not totally averse to using <txp:php>, you could quite easily do:

<txp:php>
    global $variable;
    $rs = getThings("
                SELECT `value`
                FROM
                    ".safe_pfx('custom_fields')."
                WHERE
                    `name` = 'custom_2_set'
                ORDER BY id ASC");
    $variable['cf_values'] = $rs ? implode(",", $rs) : '';
</txp:php>

replacing the 2 in custom_2_set with the number of the custom field you want and cf_values with the name of the variable you want to use on your page (template).

You’d then use:

<txp:variable name="cf_values" />

to output those values. For now, this just gives you a comma-separated list in the order you input the values, e.g. Sci-Fi,Romance,Thriller,Pre-Code.

If you want to turn that into a select dropdown, you need to use txp:variable with the attribute breakby="," to denote split the list by comma, and then wraptag, break and if desired class and html_id. Use the sort="asc" to alphabetize the sort order. For example to get your select dropdown, you could do:

<txp:variable name="cf_values" breakby="," wraptag="select" break="option" html_id="genre-chooser" />

which gives you:

<select id="genre-chooser">
    <option>Sci-Fi</option>
    <option>Romance</option>
    <option>Thriller</option>
    <option>Pre-Code</option>
</select>

TXP Builders – finely-crafted code, design and txp

Offline

#107 2024-02-18 18:14:57

amordecosmos
Plugin Author
From: London (Hometown: Vancouver)
Registered: 2004-08-03
Posts: 114
Website

Re: glz_custom_fields v2 beta for Textpattern v4.7

This is a great solution, thank you.

Offline

#108 2024-07-25 14:08:18

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 637
Website

Re: glz_custom_fields v2 beta for Textpattern v4.7

—————————————-

Edit: oops I haven’t noticed that there is already a new version that fixes these.
Anyway if you are running an old site that uses v2.0beta and upgrading to PHP 8 then this may be somehow useful to you, but firstly check the new latest version here .

—————————————-

There are 3 code changes:

1. Change this:

// Removes { } from values which are marked as default
function glz_clean_default($value)
{
    $pattern = "/^.*\{(.*)\}.*/";
    return preg_replace($pattern, "$1", $value);
}

To this:

// Removes { } from values which are marked as default
function glz_clean_default($value)
{
    $pattern = "/^.*\{(.*)\}.*/";
    return preg_replace($pattern, "$1", $value ?? '');
}

2. Comment out the glz_fButton function like this:
(It seems like we do not need it and it just throwing errors)

/*
function glz_fButton($type, $name, $contents='Submit', $value, $class='', $id='', $title='', $onClick='', $disabled = false)
{
    $o  = '<button type="'.$type.'" name="'.$name.'"';
    $o .= ' value="'.htmlspecialchars($value).'"';
    $o .= ($class)    ? ' class="'.$class.'"' : '';
    $o .= ($id)       ? ' id="'.$id.'"' : '';
    $o .= ($title)    ? ' title="'.$title.'"' : '';
    $o .= ($onClick)  ? ' onclick="'.$onClick.'"' : '';
    $o .= ($disabled) ? ' disabled="disabled"' : '';
    $o .= '>';
    $o .= $contents;
    $o .= '</button>';
    return $o;
}
*/

3. Change this:

// Convert to delimited string …
$value = implode($value, '|');

To this:

// Convert to delimited string …
$value = implode('|', $value);

Please let me know if there are any issues with the changes I have made.

Last edited by THE BLUE DRAGON (2024-07-25 14:46:49)

Offline

Board footer

Powered by FluxBB