Custom Fields
Re-Envisioned
Support General Get Custom Field in functions.php

  • Creator
    Topic
  • #23983
    Resolved clientes@interficto.com
    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;
    }
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #23987
    Long 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

    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 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 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.