How do I access Custom Field data on the PHP side of things?
-
dakotaroar
- Regular
- Posts: 21
- Joined: Thu Nov 08, 2007 3:30 pm
How do I access Custom Field data on the PHP side of things?
If I am using Custom Fields, and I want to call a variable in a template, I can use {ep_CustomField1].
What is the corresponding function in PHP? Suppose my CustomField1 = 5 in the serendipity_entryproperties table. I've tried
serendipity_fetchEntryProperties($entry['id']), but I am not sure how this array is structured, since
$variable1 = $entry_properties['ep_CustomField1'];
does not work.
Any help would be appreciated.
What is the corresponding function in PHP? Suppose my CustomField1 = 5 in the serendipity_entryproperties table. I've tried
serendipity_fetchEntryProperties($entry['id']), but I am not sure how this array is structured, since
$variable1 = $entry_properties['ep_CustomField1'];
does not work.
Any help would be appreciated.
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: How do I access Custom Field data on the PHP side of thi
Hi!
Where do you want to put that PHP code?
Try a print_r($eventData) if using inside a hook.
Regards,
Garvin
Where do you want to put that PHP code?
Try a print_r($eventData) if using inside a hook.
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
dakotaroar
- Regular
- Posts: 21
- Joined: Thu Nov 08, 2007 3:30 pm
I'm using it to set options for the SMF script I am writing, such as user ID. The user ID would be given by the person making the entry, and then the SMF post would be made by the user coinciding with that user ID.
It's a matter of getting the user ID in the custom field out into a variable so I can dump it into the script for SMF to read it.
It's a matter of getting the user ID in the custom field out into a variable so I can dump it into the script for SMF to read it.
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
Yeah, then a print_r() on the $eventData in your plugin hook should reveal you all variables you need.
Regards,
Garvin
Yeah, then a print_r() on the $eventData in your plugin hook should reveal you all variables you need.
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
dakotaroar
- Regular
- Posts: 21
- Joined: Thu Nov 08, 2007 3:30 pm
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
Please show us the code you have so far, then I might be able to understand what you're trying to do.
Regards,
Garvin
Please show us the code you have so far, then I might be able to understand what you're trying to do.
Sure, you can! You just need the id from the $eventData array in your plugin event hook.Can't I just use serendipity_fetchEntryProperties($id)? That seems to be the most appropriate way to do this.
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
dakotaroar
- Regular
- Posts: 21
- Joined: Thu Nov 08, 2007 3:30 pm
I don't know how this will help you any more, but maybe you can tell me how this entry_properties array should be called?
I already have $entry['id'] at this point. All I want to know is how to get into what I have called $entry_properties. It's probably something really stupid.
I already have $entry['id'] at this point. All I want to know is how to get into what I have called $entry_properties. It's probably something really stupid.
Code: Select all
/* ADDED CODE - PART II
*
* This actually posts the post to the SMF forum.
*We had to wait until now so we could find the PermaLink
*
*/
$entry_properties = serendipity_fetchEntryProperties($entry['id']);
$ID_MEMBER = $entry_properties['ep_CustomField1']; //This is where the CustomField1 value should go.
//$ID_MEMBER = 6;
$perma_link = serendipity_archiveURL($entry['id'], $entry['title']);
$msgBody = $msgBodytotal . '<br /><br />[url=' . $perma_link . ']Full article . . .[/url]';
$msgBody = prepBody($msgBody);-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
Where did you insert this code? I'm not understanding which file you'Re editing.
Your initial posting was talking of your own plugin file, but the code you posted cannot work on its own.
Regards,
Garvin
Where did you insert this code? I'm not understanding which file you'Re editing.
Your initial posting was talking of your own plugin file, but the code you posted cannot work on its own.
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
dakotaroar
- Regular
- Posts: 21
- Joined: Thu Nov 08, 2007 3:30 pm
I'm not talking about my own plugin. All the other coding sections of this board have big labels that say "DON'T POST IF YOU AREN'T A DEVELOPER!!!!!", so I posted it here.
I don't have time to make a plugin. Maybe someone else will later, but all I am trying to do is make it work.
This code is from functions_entries.inc.php. No, it's not the entire section.
I don't have time to make a plugin. Maybe someone else will later, but all I am trying to do is make it work.
This code is from functions_entries.inc.php. No, it's not the entire section.
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
One should NEVER need to modify core s9y files to do anything. We are fully operational through event plugins, so this is where external data calls should be done. But I can't tell you where to call what, unless you tell me exactly what you need to get working.
So if you use the PHP code at the right place, where $entries['properties'] is set (like in the PHP plugin hook "frontend_display"), you have access to the custom property fields. Also in any template file you have access. You are NOT ALLOWED to put HTML code into the PHP things, that's what the smarty template files are for.
Please take some time write a full posting that indicates what exactly you want to do how and where. You're mixing up things and postings and plans and ideas, so I (and supposedly no one else here) no longer understand what you want to do at all.
Regards,
Garvin
One should NEVER need to modify core s9y files to do anything. We are fully operational through event plugins, so this is where external data calls should be done. But I can't tell you where to call what, unless you tell me exactly what you need to get working.
So if you use the PHP code at the right place, where $entries['properties'] is set (like in the PHP plugin hook "frontend_display"), you have access to the custom property fields. Also in any template file you have access. You are NOT ALLOWED to put HTML code into the PHP things, that's what the smarty template files are for.
Please take some time write a full posting that indicates what exactly you want to do how and where. You're mixing up things and postings and plans and ideas, so I (and supposedly no one else here) no longer understand what you want to do at all.
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
dakotaroar
- Regular
- Posts: 21
- Joined: Thu Nov 08, 2007 3:30 pm
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
Simply use:
and you'll se the result. print_r is always your friend. 
Regards,
Garvin
Simply use:
Code: Select all
$props = serendipity_fetchEntryProperties(1);
print_r($props);
$props['ep_CustomField1'] should be it.This is probably some misunderstanding of PHP on my part. How do I get a value back out of this array if I know that the property I am looking for is, for example, "CustomField1"?
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
dakotaroar
- Regular
- Posts: 21
- Joined: Thu Nov 08, 2007 3:30 pm
Thank you! That is exactly what I was looking for.
Unfortunately I have run into another problem. When are the extended properties actually put into the database? I am trying to add a section of code that will run right after the entry is posted, but there seem to be no values that are accessible. I can access values from previous entries (e.g., entry['id']-1), but not from the one that was just posted. This leads me to believe that I am out of order, which is probably why I've had such a hard time with this (because I was trying to use an empty variable).
For example, if I was to use the following code from functions_entries_inc.php (in function serendipity_updertEntry()),
$props['ep_SMF_ID-number'] would come out empty.
Do database queries run by plugins run at a certain time relative to other functions? I wish to use these additional post properties to determine how the post to the SMF forum will be formatted, or if the post will be sent at all.
Thanks for your help so far, you've been very patient.
Unfortunately I have run into another problem. When are the extended properties actually put into the database? I am trying to add a section of code that will run right after the entry is posted, but there seem to be no values that are accessible. I can access values from previous entries (e.g., entry['id']-1), but not from the one that was just posted. This leads me to believe that I am out of order, which is probably why I've had such a hard time with this (because I was trying to use an empty variable).
For example, if I was to use the following code from functions_entries_inc.php (in function serendipity_updertEntry()),
Code: Select all
$res = serendipity_db_insert('entries', $entry);
if ($res) {
$entry['id'] = $serendipity['lastSavedEntry'] = serendipity_db_insert_id('entries', 'id');
if (is_array($categories)) {
foreach ($categories as $cat) {
if (is_numeric($cat)) {
serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entrycat (entryid, categoryid) VALUES ({$entry['id']}, {$cat})");
}
}
}
serendipity_insertPermalink($entry);
//start my added code
$id = $entry['id'];
$props = serendipity_fetchEntryProperties($id);
print_r($props);
$ID_MEMBER = $props['ep_SMF_ID-number'];Do database queries run by plugins run at a certain time relative to other functions? I wish to use these additional post properties to determine how the post to the SMF forum will be formatted, or if the post will be sent at all.
Thanks for your help so far, you've been very patient.
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
The properties are stored in the backend_publish / backend_save hooks. You can access the properties at that point by looking into $serendipity['POST'].
If you really need it from the DB,you can use the hook "'backend_trackbacks'".
HTH,
GArvin
The properties are stored in the backend_publish / backend_save hooks. You can access the properties at that point by looking into $serendipity['POST'].
If you really need it from the DB,you can use the hook "'backend_trackbacks'".
Yes, they do-plugin API events are called in a linear way.Do database queries run by plugins run at a certain time relative to other functions?
HTH,
GArvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
dakotaroar
- Regular
- Posts: 21
- Joined: Thu Nov 08, 2007 3:30 pm