Get Custom Field in functions.php

Support General Get Custom Field in functions.phpResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #23983
    clientes@interficto.com[email protected]
    Participant

    Hello, can you help me please. I want get the custom field in functions file. What is the best approach?

    The next no work for me

    
    function query_crm_usados_interna(){
     $meta = rwmb_meta( 'if_usados_usad_id',get_the_ID() )
    return $meta;
    }
    
    #23987
    Long NguyenLong Nguyen
    Moderator

    Hi,

    If you needn't the extra arguments, please leave the second argument empty.

    function query_crm_usados_interna(){
     $meta = rwmb_meta( 'if_usados_usad_id', '', get_the_ID() )
    return $meta;
    }

    Get more details in the documentation https://docs.metabox.io/rwmb-meta/#arguments.

    #24206
    clientes@interficto.com[email protected]
    Participant

    Hello, thank you for your answer, but this code doesn't work in functions.php I am reading and the get_the_id() function only work in the loop, and I am not using the loop. maybe can you help me please?

    #24207
    Long NguyenLong Nguyen
    Moderator

    Hi,

    If you do not use the function in the loop, just add a parameter to the function like the helper function.

    function query_crm_usados_interna( $post_id ){
     $meta = rwmb_meta( 'if_usados_usad_id', '', $post_id )
     return $meta;
    }

    then pass the post ID when calling the function

    
    echo query_crm_usados_interna( 1234 );
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.