• Resolved Jeshua

    (@jeshuavs1)


    Hi Team of Pods. I’ve a question.

    I’m wondering get the raw value of a relationship field with an array my code is:

    function ver_assets () {
        
        $formacion_assets = pods( 'formacion', get_the_id() );
        
      $argu = array( 
                'name' => 'assets_activos', 
                'single' => false, 
                'raw' => false, 
                'in_form' => true, 
                'raw_display' => false,
                'display' => false,
                'get_meta' => false, 
                'output' => null, 
                'deprecated' => false, 
            );
            
    $insertar_assets = $formacion_assets->field( $argu );
        
        echo '<p>' . $insertar_assets . '</p>';
        
    }
    add_shortcode ('assets_sc', 'ver_assets');

    The thing is that if a set to true “in_form” the call returns me for example (in this case the relationship field is with a pod, in this case returns me the post id with the in_form): “1234 and 5678” Then I want that returns me “1234, 5678” I really don’t figure it out how to achieve this. Thanks of beforehand.

    • This topic was modified 6 years, 11 months ago by Jeshua.
    • This topic was modified 6 years, 11 months ago by Jeshua.
    • This topic was modified 6 years, 11 months ago by Jeshua.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Jeshua

    (@jeshuavs1)

    I need that format for the value because I need to insert it in a query:

    function query_manuales ( $query, $widget ) {
    
        $formacion_assets = pods( 'formacion', get_the_id() );
               
        $insertar_assets = $formacion_assets->display( 'assets_activos' );
        
        $query->set( 'post_type', ['formacion'] ); 
        $query->set('post__in', [ $insertar_assets ] );
    }
    add_action( 'elementor/query/assets_query', 'query_manuales', 10, 2 );

    So the post__in method needs an array of post id’s.

    Thanks for your help of beforehand. If I’m missing something, please I’ll be glad if you let me know.

    • This reply was modified 6 years, 11 months ago by Jeshua.
    • This reply was modified 6 years, 11 months ago by Jeshua.
    Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    field() will return an array of relationship data by default. If you only need IDs, just pass the argument 'output' => 'ids'

    Thread Starter Jeshua

    (@jeshuavs1)

    Thanks for your answed Scott. But didn’t work in the query. My changed code:

    function query_manuales ( $query, $widget ) {
    
        $formacion_assets = pods( 'formacion', get_the_id() );
        
         $argu = array( 
                'name' => 'assets_activos', 
                'output' => 'ids', 
            );
        $insertar_assets = $formacion_assets->field( $argu );
    
        $query->set( 'post_type', ['formacion'] ); 
        $query->set('post__in', [ $insertar_assets ] );
    
    }
    add_action( 'elementor/query/assets_query', 'query_manuales', 10, 2 );

    I example, if I change $insertar_assets in $query->set('post__in', [ $insertar_assets ] ); by $query->set('post__in', [ 1234 , 5678 , 9123] ); In the place where I want to use the query it works. That show three posts, that is the same thing that I’m wondering with the field (assets_activos) in my pod (formacion).

    • This reply was modified 6 years, 11 months ago by Jeshua.
    • This reply was modified 6 years, 11 months ago by Jeshua.
    Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    You’ll want to not use [ $insertar_assets ] and instead just pass it directly as $insertar_assets since it will come back as an array already.

    Thread Starter Jeshua

    (@jeshuavs1)

    It works!. Obviusly… honestly I don’t know how I passed that. Hahaha Thanks Scott!!.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Get an array from a relationship field’ is closed to new replies.