- This topic is empty.
-
AuthorPosts
-
December 18, 2011 at 12:49 am #35722
angelazou
ParticipantHi,
I’m tweaking a plugin for it to work for a website that I’m creating. The PHP code is stored at http://jsfiddle.net/zvN2p/ (I know, JSfiddle doesn’t work with PHP. Just a placeholder). Anyway, I’m focusing on what happens when the custom_field is set to true in the shortcode. There are two issues with the PHP code:
1- Sounds silly enough. I can’t get the counter to increment itself. It’s currently placed inside the foreach loop, but it doesn’t increment when the posts show. I have absolutely no idea why.
2- I can’t get the values of the custom fields using get_post_meta($post, $key, true), where $key is replaced with $index and $doc_no, the 2 instances of the custom field key name for whose value I wish to obtain. When I run it, it just show up empty. Could it have something to do with the key name being a Unicode character?Angela
December 18, 2011 at 11:32 pm #93071angelazou
Participantyoho?
December 19, 2011 at 2:46 am #93079jamygolden
MemberNext time you want to paste php, I suggest using something like Pastebin or something similar since it’s meant for simple code pasting and it has syntax highlighting too.
1- As for the $counter problem, it’s due to the keyword ‘continue‘ you’ve used within the
if ($custom_field == 'true')
statement. If you remove that, it should work. Also, it’s common practice to use$counter++;
instead of$counter += 1;
2 – I’m not sure about this problem, I would recommend trying it with normal utf-8 characters to see if it works before trying other things.December 19, 2011 at 4:08 am #93080angelazou
ParticipantI found that these codes are used ( in functions.php ) in Suffusion to handle Custom Field. The following is the original code, but I’m going to add (as a testing purpose to see if the UTF-8 character are the culprit) 2 more fields into the array and assign values to them to see if they show up.
But I’m pretty clueless at this point, so any tips are appreciated.
add_action("save_post", "suffusion_save_post_fields");
add_action("publish_post", "suffusion_save_post_fields");
function suffusion_save_post_fields($post_id) {
$suffusion_post_fields = array('thumbnail', 'featured_image', 'suf_magazine_headline', 'suf_magazine_excerpt', 'suf_alt_page_title', 'meta_description', 'meta_keywords', 'suf_nav_unlinked', 'suf_pseudo_template', 'suf_hide_page_title');
if (isset($_POST)) {
foreach ($suffusion_post_fields as $post_field) {
if (isset($_POST[$post_field])) {
$data = stripslashes($_POST[$post_field]);
}
else {
$data = '';
}
if (get_post_meta($post_id, $post_field) == '') {
add_post_meta($post_id, $post_field, $data, true);
}
else if ($data != get_post_meta($post_id, $post_field, true)) {
update_post_meta($post_id, $post_field, $data);
}
else if ($data == '') {
delete_post_meta($post_id, $post_field, get_post_meta($post_id, $post_field, true));
}
}
}
}
December 19, 2011 at 4:40 am #93082angelazou
ParticipantI read the codex again on Custom Field, and I found out where they are stored in the database.
Currently I can’t save any of the custom fields (although the ones I previously worked on seemed to be remembered if I click the drop down list to get a list of existing Custom Field Keys) nor can I update them. They all disappear once I hit the Update/Publish button.
Here is what I did to troubleshoot the issue:
1- Created a test post that contain values for already defined Custom Keys (specified in the array of the function), as well as values that I want to define myself.
2- Modify the plugin to show both results, but failed. I also removed my 2 new custom key definition from the array, and tried again, but also failed because I can’t the values anymore once I update the post.
3- I checked into the postmeta table, where the custom fields are suppose to be stored in (according to the codex ‘implementation details’ section), but I couldn’t find the keys/values either.
My conclusion: at this point, the question becomes how can I create a custom key/value pair?Angela
PS: I’ve also changed the key name from Chinese characters to English characters, but I still can’t see the values after updating the post.
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.