Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Can if_custom_field use IDs rather than names?
I know if_custom_field
has the attribute name
to select the relevant field, but is there a way I can check an ID (01 to 10) instead?
Offline
#2 2012-11-22 13:02:42
- milosevic
- Member
- From: Madrid, Spain
- Registered: 2005-09-19
- Posts: 390
Re: Can if_custom_field use IDs rather than names?
If_custom_field name=“custom_10”.
No matter if your custom field number 10 is named “price” or whatever: it is still the custom filed number 10also.
So you can use names like “custom_” plus the ID number for callind your custom fields.
<txp:rocks/>
Offline
Re: Can if_custom_field use IDs rather than names?
Thank you, Jorge – that’s great news!
Offline
Re: Can if_custom_field use IDs rather than names?
Hi Jorge – I am not having much success with name="custom_xx"
perhaps you can help me with my syntax. I have tried:
<txp:custom_field default=”“ name=“custom_1” />
…and also I have tried:
<txp:custom_field default=”“ name=“custom_01” />
Nothing is displayed — I know there are contents in the field. Do you have any ideas that might help?
Thank you in advance
Offline
#5 2012-11-23 22:01:25
- milosevic
- Member
- From: Madrid, Spain
- Registered: 2005-09-19
- Posts: 390
Re: Can if_custom_field use IDs rather than names?
Sorry, gaekwad, I was wrong: calling a custom field by “custom_NUMBER” only works when on the param “sort” of the txp:article_custom tag. You are right, it don’t works the way I told you with txp:custom_field.
Any way you can try smd_query plugin. It searchs for content directly on database tables and fields, and the custom fields database fields are named “custom_1”, “custom_2”, etc. so it must work yes or yes, but I can’t give you an example of how to retrieve a custom field with smd_query because I have never use it already.
<txp:rocks/>
Offline
Re: Can if_custom_field use IDs rather than names?
Pete testing txp limits? :) You can address named custom fields by ID
through $prefs['custom_ID_set']
variable:
<txp:custom_field name='<txp:php>global $prefs; echo $prefs["custom_7_set"];</txp:php>' />
I can not imagine why would you need it, but in case you want to output all custom fields, etc_query
can help:
<txp:etc_query globals="prefs" parse="both">
<txp:etc_query data="[1..10]" parse="">
<txp:custom_field name="{{?custom_{?}_set}}" />
</txp:etc_query>
</txp:etc_query>
Offline
Re: Can if_custom_field use IDs rather than names?
milosevic wrote:
Any way you can try smd_query plugin.
You, sir, have just given me a reason to try another of Stef’s plugins – thanks!
Offline
Re: Can if_custom_field use IDs rather than names?
etc wrote:
Pete testing txp limits? :)
Oleg, I have absolutely no idea what you mean… ;)
etc wrote:
<txp:custom_field name=’<txp:php>global $prefs; echo $prefs[“custom_7_set”];</txp:php>’ />
I like this a lot, thank you. Real men do it in core, right? Right. Maybe. Perhaps some real men could comment, I’m not in a position to say.
Last edited by gaekwad (2012-11-24 11:34:54)
Offline
Re: Can if_custom_field use IDs rather than names?
gaekwad wrote:
Real men do it in core, right?
Isn’t <txp:php>
a txp tag? Just curious, why you need it?
Offline
Re: Can if_custom_field use IDs rather than names?
etc wrote:
Isn’t
<txp:php>
a txp tag? Just curious, why you need it?
Yes, exactly – I prefer to do things in core to avoid the plugin dependencies where possible.
I’ll tell you why I need it: I’m starting to use excerpts and custom fields extensively. I want to use excerpt
for the meta description and some of the custom fields for legal disclosure. I need to know which articles have what custom fields set and which have excerpts, and I figured the quickest way to achieve this would be by using a large table. So, I’m making this (work in progress – may disappear when it’s finished):
That lists the article specifics for each article, and I can see from skimming which articles require work. If it’s working properly when I’ve finished, I’ll release the code for it, but hopefully you get the general idea of what I want to achieve.
Last edited by gaekwad (2012-11-24 12:25:55)
Offline
Re: Can if_custom_field use IDs rather than names?
For a large table like this I would certainly use smd_query
rather than <txp:article_custom />
, it should be much faster.
Offline
Re: Can if_custom_field use IDs rather than names?
Thanks, Oleg – I’ll definitely check it out. As it stands right now, rendering that page takes about 8mb of memory on a live server — I’ll do an A-B test and see how it fares with smd_query
.
Offline