- This topic has 16 replies, 4 voices, and was last updated 7 years, 10 months ago by
jsperl.
-
AuthorPosts
-
-
March 6, 2014 at 8:23 pm #1517
jsperlMemberHi, could you point me to a good general tutorial for beginners on how to display field content on the front end? Thanks!
BTW the forum here seems riddled with broken links…every time I think I’ve found an answer (like, say, for this topic) it turns out the page doesn’t exist…very frustrating.
-
March 6, 2014 at 10:40 pm #1520
SteveKeymaster@jsperl– Frontend forms are not completed yet. Showing field data on the front end is the same as any meta. For Post Meta use would use get_post_meta.
Broken links should be fixed.
-
March 7, 2014 at 3:57 am #1527
jsperlMemberHi Steve, thanks for answering…I really phrased the question wrong…what I really meant was displaying the field data on the front end as you referenced in your 2nd sentence. I’m not very experienced with writing code to extract and display data using get_post_meta and was looking for a good tutorial about ways to do that (I figured it would be more a WordPress thing rather than Piklist-specific but I just thought you guys might know a good resource…but I can Google it)…although in my most immediate case, it’s taxonomy custom field values I’m looking to display.
-
March 7, 2014 at 10:35 am #1529
SteveKeymaster@jsperi– WordPress doesn’t have the equivalent to
get_post_metafor terms… but Piklist does. We added aget_term_metafunction that works just likeget_post_meta. Use the get_post_meta docs as a guide, and replace $post_id with the $term_id.If you still have problems let us know, we’re here to help.
-
March 7, 2014 at 2:12 pm #1532
jsperlMemberOk great…that gives me a good direction to start…thanks!
-
March 10, 2014 at 7:24 am #1537
talhamalikMemberHI, I have used piklist method and create custom post type, which is created successfully. Now in the second step i follow given steps and passes piklist parameters like
/*
Title: My Demo Metabox
Post Type: post
*/
piklist(‘field’, array(
‘type’ => ‘text’
,’field’ => ‘text’
,’label’ => ‘Text Box’
,’description’ => ‘Field Description’
,’value’ => ‘Default text’
,’help’ => ‘This is help text.’
,’attributes’ => array(
‘class’ => ‘text’
)
));After all in CMS i only see the field label, field description, help etc but the field text box is not showing.
I have tried all fields like editor, text, select etc all boxs are not showing… whats the issue.. -
March 10, 2014 at 9:34 am #1538
SteveKeymaster@talhamalik– This code is working for me. Try changing
’field’ => ‘text’to something else since “text” is too generic and might be conflicting with another field of the same name.’field’ => ‘my_text_box’. -
March 11, 2014 at 3:35 am #1541
talhamalikMemberHI Steve,Thanks for answering my problem..
I have found the point.. when i copy the piklist folder structure to the theme folder accourding to tutorial, the fields are missing infact the label description, help etc are not missing..
and also the piklist demos fields are also missing after copying folder structure to the theme folder,
i turn on the debug mode there are 2 notice and 3 warnings which are…
i am totally stucked..WARNING: C:\xampp\htdocs\wp-task4\wp-content\plugins\piklist\includes\class-piklist.php:272 – include(C:\xampp\htdocs\wp-task4\wp-content\themes\twentythirteen\piklist): failed to open stream: Permission denied
WARNING: C:\xampp\htdocs\wp-task4\wp-content\plugins\piklist\includes\class-piklist.php:272 – include(): Failed opening ‘C:\xampp\htdocs\wp-task4/wp-content/themes/twentythirteen/piklist’ for inclusion (include_path=’.;C:\xampp\php\PEAR’)
WARNING: C:\xampp\htdocs\wp-task4\wp-content\plugins\piklist\includes\class-piklist.php:230 – Invalid argument supplied for foreach()NOTICE: C:\xampp\htdocs\wp-task4\wp-content\plugins\piklist\includes\class-piklist.php:208 – Undefined variable: _part
NOTICE: C:\xampp\htdocs\wp-task4\wp-content\plugins\piklist\includes\class-piklist.php:210 – Undefined variable: _partand this warning exists with out all above queries which is
WARNING: C:\xampp\htdocs\wp-task4\wp-content\plugins\piklist\includes\class-piklist.php:230 – Invalid argument supplied for foreach()
-
March 11, 2014 at 10:00 am #1542
SteveKeymaster@talhamalik– It looks like the /piklist/ folder you created twentythirteen doesn’t have the proper permissions set. You will need to adjust them so Piklist can access the appropriate files. Here is a good overview on folder/file permissions >
-
March 14, 2014 at 3:32 pm #1554
jsperlMemberSorry to be a pest, but I’m missing something here and am really stuck. My goal is to retrieve the URL of an image from the currently queried taxonomy term. I’ve adde an image field to my custom taxonomy with the following Piklist code:
piklist('field', array( 'type' => 'file' ,'field' => 'upload_media' ,'scope' => 'post_meta' ,'label' => __('Add Image','piklist') ,'description' => __('Add an icon image to this category.','piklist') ,'options' => array( 'modal_title' => __('Add Image','piklist') ,'button' => __('Add Image','piklist') ) ));Would you mind posting a code snippet of exactly how to use
get_term_metato extract the attached image URL from the currently queried taxonomy term? I’ve tried figuring it out from the WP codex but the seemingly applicable “get_” functions all seem to require a known term ID in the arguments…and this is where my inexperience with WP functions is getting me stumped. Here is a URL showing what I’m trying to accomplish: http://sccnew.speedofc.com/tb-staging/This is a listing of top-level categories from a custom taxonomy that I have created and displayed using the Types and Views plugin. My goal is to display the image attached to each category (via Piklist) next to each description below the title. Seems like it should be very simple. I have spent many hours Googling and crawling through the WP codex and the answer still eludes me.
-
March 14, 2014 at 4:30 pm #1555
KevinKeymaster@jsperl-
Not a problem, lets walk through this. First you need an ID for the term, there are a variety of ways to get this, for example if you are fetching the terms for a post you can use https://codex.wordpress.org/Function_Reference/wp_get_object_terms or you can just fetch the terms from a taxonomy with https://codex.wordpress.org/Function_Reference/get_terms There are other ways to get the ID depending on where you are and what your working with, I would suggest taking a look over the Codex to see the other methods (Also be sure to check out the loop documentation https://codex.wordpress.org/The_Loop). Now once you have the term id you can get the attachment id (your uploaded image) by using
$the_term = get_term_meta($term->term_id, 'upload_media', true);Now this will return the ID for your attachment and you can now fetch it using something like this https://codex.wordpress.org/Function_Reference/wp_get_attachment_url or any other function that fetches attachments and their data (just depends what your after).
I hope this was helpful, if you have any other questions don’t hesitate to ask.
Thanks,
Kevin
-
March 16, 2014 at 11:49 pm #1561
jsperlMemberThanks Kevin, but it’s that first step (getting the ID of the term) that I can’t figure out…I’ve read the codex descriptions many times and tried many of the examples but still not getting it. Here are a couple of things I’ve tried the do not work:
$queried_object = get_queried_object(); $term_id = $queried_object->term_id;and
$term = get_term( term_id, 'item-category' ); $term_id = $term->term_id;What I don’t understand is what to put in place of “term_id” in the get_term() function in order to get the current term ID.
Is there any way you could post a snippet of exactly how to do this? My previous post describes the context and what I’m trying to do. Hope it’s clear enough. Thanks!
-
March 16, 2014 at 11:56 pm #1562
jsperlMemberI’ve also tried
$term = get_term( get_queried_object(), 'item-category' ); $term_id = $term->term_id; -
March 17, 2014 at 11:28 am #1563
SteveKeymaster@jsperl– Unless your question changed from getting the image url, I don’t think you need to use get_term. This should work.
GET THE TERM ID:
$queried_object = get_queried_object(); $term_id = $queried_object->term_id;GET THE IMAGE ID
$image_id = get_term_meta( $term_id, 'upload_media');GET IMAGE URL
$image_url = wp_get_attachment_url($image_id);The upload field can save multiple images. If so, $image_id will be an array and you will need to loop through it.
-
March 17, 2014 at 2:29 pm #1566
jsperlMemberThanks Steve! So I was on the right track with the `get_queried_object();’ function. I still can’t get it to display anything though, but I’m not sure it’s a Piklist issue. I’m trying to output this in a Toolset Views taxonomy view, and since Views doesn’t allow php directly I have to wrap it in a shortcode first:
function cat_icon() { $queried_object = get_queried_object(); $term_id = $queried_object->term_id; $image_id = get_term_meta( $term_id, 'upload_media' ); $image_url = wp_get_attachment_url($image_id); print $image_url; } add_shortcode( 'caticon', 'cat_icon' );Then I’m trying to add it to my view with
<img src="[caticon]" height="75" width="75" />Which normally should work in Views, but nothing is displayed. In troubleshooting whether my view is taking the shortcode I’ve tried something simple like
function cat_icon() { print "Hola!"; } add_shortcode( 'caticon', 'cat_icon' );And that DOES work when added to my view…which makes me think wrapping it in shortcode is not the problem. I’m also not sure what the best way of outputting $image_url is, print, echo, or return…I’ve tried all 3 to no avail. Anyway, I don’t want to take too much of your time from developing this great product as I’m not even sure it’s a Piklist issue…I’m going to post on the Toolset forum to see I can get any insight there.
-
March 17, 2014 at 9:49 pm #1567
SteveKeymasterNot really sure how “Views” works, but I doubt it’s a Piklist issue since all it saves is the attachment ID.
I would add this to to the shortcode to see if get_queried_object() is returning data.
var_dump($queried_object);If yes, then try this with each line in your shortcode function to see what is not returning data.
-
March 18, 2014 at 12:38 am #1568
jsperlMembervar_dump($queried_object);returns null so it appears I have more work to do…will take it up with the Views people…I sure hope I can get Piklist and Views to play nice together!
-
-
AuthorPosts
- You must be logged in to reply to this topic.