• Hello, I need to show and Advanced Custom Field on the store list.
    This is what I’m trying to do:

    the_field(‘pdf_link_txt’, $store_id )

    The problem is that $store_id has no value, so the ACF isn’t displayed.

    I tried using the <%= id %> instead of $store_id, but this variable is client side only so does not work for ACF.

    Any clue? Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Tijmen Smit

    (@tijmensmit)

    You need to use this filter.

    Something like this should work.

    add_filter( 'wpsl_store_meta', 'custom_store_meta', 10, 2 );
    
    function custom_store_meta( $store_meta, $store_id ) {
        
        $store_meta['pdf_link_txt'] = the_field(‘pdf_link_txt’, $store_id );
        
        return $store_meta;
    }

    Do make sure to also use ‘pdf_link_txt’ in the template itself.

    • This reply was modified 5 years, 6 months ago by Tijmen Smit.
    Thread Starter psartorio

    (@psartorio)

    Hi Tijmen, unfortunately I can’t make this work.
    This Is my code:

    $store_id = '<%= id %>';
          
            echo '<p>' . the_field('pdf_link_txt', $store_id ).'</p>';

    As I said, the value of my $store_id is not valid server-side, so the ACF part of the code (the_field) isn’t working.
    What I’m not able to do is get the actual store ID and put it into a PHP variable.
    How I can get the store_id? Thanks

    Plugin Author Tijmen Smit

    (@tijmensmit)

    You want to get a value from ACF and make that show up in the template code, right?

    So you use this filter and replace ‘my_textinput’ with the name of your custom value, which in this case we can call ‘pdf_link_txt’. So you can replace the code from line 31 – 33 with the code below.

    $listing_template .= "\t\t\t" . '<% if ( pdf_link_txt ) { %>' . "\r\n";
    $listing_template .= "\t\t\t" . '<p><a href="<%= pdf_link_txt %>">PDF</a></p>' . "\r\n";
    $listing_template .= "\t\t\t" . '<% } %>' . "\r\n";

    To give the pdf_link_txt a value you need to use the code below as well.

    add_filter( 'wpsl_store_meta', 'custom_store_meta', 10, 2 );
    
    function custom_store_meta( $store_meta, $store_id ) {
        
        $store_meta['pdf_link_txt'] = the_field(‘pdf_link_txt’, $store_id );
        
        return $store_meta;
    }

    This does assumes the_field returns a value instead of echoing it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add ACF to store list’ is closed to new replies.