How to get Custom Field label
-
I have many custom fields which I am showing on different pages for the product. I have any array of field which i want to show but but i can’t find way to get same field label.
Can any one help.
-
Hi @vaibhav26
Please see this page: https://docs.pods.io/code/pods/field/field-notation-options/#Pod_Information
Cheers, Jory
Thanks for quick reply @keraweb
But I’m using name(slug) of the field to using
get_post_meta
for value and for that particular name i want label.Can you please let me know how to use it via sample code.
Thank you
Hi @vaibhav26
There are not default WordPress functions for this purpose, that is why I referred you to our field notations.. You can then use it with
pods_field()
for example.
https://docs.pods.io/code/field-functions/pods_field/Cheers, Jory
Hi @keraweb
Still no luck. I have name(or slug) of
purity
a pods field. I usedget_post_meta
to gets it value but when I tried to get label by the function you referenced it returns its value.this how I used it.
<?php $pods = pods('pod_name','purity');?> print_r(pods_field($pods));
this code give me the its value but I need its Label. I don’t know where I am getting wrong.
Have a look.
Thank YouHi @vaibhav26
You are trying to combine to different things.
Did you read the documentation?It’s either:
pods_field( 'pod_name', null, '_field.my_field_name.label' );
or:
pods( 'pod_name' )->field( '_field.my_field_name.label' );
The first would basically translate to the latter.
Cheers, Jory
Hi @vaibhav26
I’m sorry, it appears an object ID or any form of context is required.
So it would be:
pods_field( 'pod_name', OBJECT_ID, '_field.my_field_name.label' );
or
pods( 'pod_name', OBJECT_ID )->field( '_field.my_field_name.label' );
Cheers, Jory
Okay @keraweb , But how do I get object_Id via name of the pods field.
for example if I use this
$pod = pods('pod_name', 'purity');
I got this result
Pods Object ( [iterator:Pods:private] => [data] => PodsData Object ( [fetch_full] => 1 [api] => PodsAPI Object ( [display_errors] => 1 [pod_data] => [pod] => [format] => [deprecated:PodsAPI:private] => ) [pod_data] => [table_info] => [id] => purity [aliases] => Array ( ) [row_number] => -1 [rows] => [row] => [insert_id] => [total] => [total_found] => [total_found_calculated] => [page_var] => pg [page] => 1 [limit] => 15 [offset] => 0 [pagination] => 1 [search] => 1 [search_var] => search [search_mode] => int [search_query] => [search_fields] => Array ( ) [search_where] => Array ( ) [filters] => Array ( ) [params] => Array ( ) [traversal] => Array ( ) [traverse] => Array ( ) [sql] => [total_sql] => ) [alt_data] => [row_override] => Array ( ) [display_errors] => 1 [pod_data] => [ui] => Array ( ) [page_template] => [body_classes] => [meta] => Array ( ) [meta_properties] => Array ( ) [meta_extra] => [deprecated] => )
I have only names of field not the id. Is there any possible to get that.
Thank you
Hi @vaibhav26
Aren’t you in a current post loop or post singular page?
If so, useget_the_ID()
https://developer.www.ads-software.com/reference/functions/get_the_id/If you arent then even an empty array would do.
Cheers, Jory
Sorry to a say I’m getting the id but the `pods_field( ‘pod_name’, get_the_ID(), ‘_field.my_field_name.label’ );
or
pods( ‘pod_name’, get_the_ID() )->field( ‘_field.my_field_name.label’ );`Didn’t giving me the result its always an empty string and I’m trying to show them at single product page of woocommerce.
Hi @vaibhav26
Just to be sure, you did change
pod_name
andmy_field_name
to the correct names right?Cheers, Jory
On a side note, I just heard that our next release will make this a bit easier.
PHP function example:echo pods_data_field( 'your_pod', '_field.my_field_name.label' );
Note that this function is new and won’t work in 2.9.3!
Cheers, Jory
- The topic ‘How to get Custom Field label’ is closed to new replies.