• Resolved vaibhav26

    (@vaibhav26)


    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.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    Thread Starter vaibhav26

    (@vaibhav26)

    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

    Plugin Author Jory Hogeveen

    (@keraweb)

    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

    Thread Starter vaibhav26

    (@vaibhav26)

    Hi @keraweb

    Still no luck. I have name(or slug) of purity a pods field. I used get_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 You

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @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

    Thread Starter vaibhav26

    (@vaibhav26)

    hi @keraweb ,
    I have tried both of your solution but it gives nothing in return.

    • This reply was modified 2 years, 2 months ago by vaibhav26.
    Plugin Author Jory Hogeveen

    (@keraweb)

    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

    Thread Starter vaibhav26

    (@vaibhav26)

    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

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @vaibhav26

    Aren’t you in a current post loop or post singular page?
    If so, use get_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

    Thread Starter vaibhav26

    (@vaibhav26)

    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.

    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @vaibhav26

    Just to be sure, you did change pod_name and my_field_name to the correct names right?

    Cheers, Jory

    Plugin Author Jory Hogeveen

    (@keraweb)

    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

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘How to get Custom Field label’ is closed to new replies.