Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-01-13 06:41:22

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 858
Website

article_custom & glz custom fields

OK – I’ve posted this here, because I’m not sure if it is plugin related or my tag syntax related.

I created a Multi-Select in glz_custom_fields with 4 options: “mens, womens, juniors, general”. Then on my page I have 4 corresponding divs, one for each of the options.

The I am using an article_custom tag like below for each option (only womens shown):

<txp:article_custom form="pb-menu-item" limit="5" HomeBoxes="womens" wraptag="ul" break="li" />

What I was expecting was that if all options were selected, then the article would appear in all 4 divs – but this isn’t happening.

I also made a box and used this tag syntax:

<txp:article_custom form="pb-menu-item" limit="5" HomeBoxes="mens,womens,juniors,general" wraptag="ul" break="li" />

but nothing showed there when all options were selected in an article.

Am I having a friday blonde moment or will this just never work?

btw – if I only select one option – it works (except for the only the first), 2 do not work, 3 do not work.

Last edited by tye (2012-01-13 06:42:10)

Offline

#2 2012-01-13 09:10:01

phuture303
Member
Registered: 2008-09-14
Posts: 127

Re: article_custom & glz custom fields

Hi Tye,

I remember that I’ve experienced similar problems when filtering articles via custom fields which are not pure text inputs but multiselect or radio buttons. Seems not to work properly :-(

You could use smd_if instead, that worked for me.

Offline

#3 2012-01-13 12:10:06

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,259

Re: article_custom & glz custom fields

phuture303 wrote:

You could use smd_if instead, that worked for me.

Probably because of its contains operator. If you look at the contents of any such custom field in your database it looks like mens|womens, so HomeBoxes="womens" can never be true for multiple selections.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#4 2012-01-13 12:17:30

phuture303
Member
Registered: 2008-09-14
Posts: 127

Re: article_custom & glz custom fields

Yeah, I think I used the “contains” operator at that time, you’re right!

But in this case you would also have problems with “mens” because this string is contained in “mens” as well as in “womens”. Tye probably could solve that with a multiselect like this:

  • 1-mens
  • 2-womens
  • 3-juniors

and check for the number 1,2,3 which is used in every item only once.

Last edited by phuture303 (2012-01-13 12:18:07)

Offline

#5 2012-01-13 12:21:10

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,259

Re: article_custom & glz custom fields

phuture303 wrote:

But in this case you would also have problems with “mens” because this string is contained in “mens” as well as in “womens”.

Really intent! :)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#6 2012-01-13 12:49:29

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: article_custom & glz custom fields

Hi,
I think smd_if should not be used in this case because you’ll first have to fetch every article from the db and then filter them. This will work but could be overkill in performance terms.
Probably is al lot more efficient to use smd_query instead. Something like this should work:

<txp:smd_query
    query ="SELECT title, excerpt, url_title, posted FROM textpattern WHERE custom_x LIKE '%womens%' AND Status='4' ORDER BY posted DESC"
	wraptag="ul" break="li" limit="100">
	<article>
		<header><h1><a href = '<txp:site_url />{url_title}'>{title}</a></h1></header>
		{posted}
		{excerpt}
	</article>
</txp:smd_query>

[replace the ‘x’ in custom_x with the actual number]

Even in this case, though, there is the issue with ‘mens’ and ‘womens’ so David’s suggestion to rename fields still stands true.

Offline

#7 2012-01-13 13:06:03

phuture303
Member
Registered: 2008-09-14
Posts: 127

Re: article_custom & glz custom fields

Hi redbot,

thanks, good point about the performance! Just a question from a MySQL-Newbie:

If I put the smd_if-filtering into a <txp:article_custom section="mysection">-container will it still fetch every article from the database or just only the articles from mysection?

Offline

#8 2012-01-13 13:32:17

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: article_custom & glz custom fields

phuture303 wrote:

…If I put the smd_if-filtering into a <txp:article_custom section="mysection">-container will it still fetch every article from the database or just only the articles from mysection?

Yes, in this case you’ll fetch only articles belonging to mysection so your solution (smd_if) could be more acceptable (depending on how many articles mysection contains of course).

Last edited by redbot (2012-01-13 13:33:34)

Offline

#9 2012-01-13 13:51:13

phuture303
Member
Registered: 2008-09-14
Posts: 127

Re: article_custom & glz custom fields

redbot wrote:

Yes, in this case you’ll fetch only articles belonging to mysection so your solution (smd_if) could be more acceptable (depending on how many articles mysection contains of course).

Okay, in my case there are only up to 25 articles in “mysection” – I think that should be okay… :-)

Have a nice weekend!
David

Last edited by phuture303 (2012-01-13 13:51:56)

Offline

#10 2012-01-13 14:14:30

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: article_custom & glz custom fields

phuture303 wrote:

Okay, in my case there are only up to 25 articles in “mysection” – I think that should be okay… :-)

Yes, that should be okay… :-)
I think you should begin to worry when there are some hundreds (or thousands) articles in your db.

Have a nice weekend you too

Offline

#11 2012-01-13 17:30:27

sacripant
Plugin Author
From: Rhône — France
Registered: 2008-06-01
Posts: 479
Website

Re: article_custom & glz custom fields

IF

<txp:smd_query
    query ="SELECT title, excerpt, url_title, posted FROM textpattern WHERE custom_x LIKE '%womens%' AND Status='4' ORDER BY posted DESC"
	wraptag="ul" break="li" limit="100">
	<article>
		<header><h1><a href = '<txp:site_url />{url_title}'>{title}</a></h1></header>
		{posted}
		{excerpt}
	</article>
</txp:smd_query>

WORKS

try may be :

<txp:article_custom form="pb-menu-item" limit="5" HomeBoxes="%womens%" wraptag="ul" break="li" />

The custom_fied attribut use SQL Like Operator

Offline

#12 2012-01-13 18:00:58

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: article_custom & glz custom fields

sacripant wrote:

…try may be…

Genius.

edit Thank you sacripant (and Jukka) for the tip!

Last edited by redbot (2012-01-13 18:43:40)

Offline

Board footer

Powered by FluxBB