Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Kenneth Feldman

    (@kenneth-feldman)

    Ultimately, I have a page template file where I’d like to have a PHP code which lists out events by a “dynamic” tag.

    So I’d need the PHP equivalent of:

    [events_list tag=”variable”]

    …where the variable is provided by a field from the Advanced Custom Fields:

    <?php the_field('isbn_number'); ?>

    Thread Starter Kenneth Feldman

    (@kenneth-feldman)

    This doesn’t work — and I don’t know enough how to fix or do other way:

    <?php echo do_shortcode( '[events_list tag="<?php the_field('isbn_number'); ?>"]' ); ?>

    You can’t put a PHP tag inside another PHP tag. Try something like this:

    <?php
    $this_tag = the_field('isbn_number');
    do_shortcode( '[events_list tag="'.$this_tag.'"]');
    ?>

    The first line may need to be changed because you need to get the value without immediately echoing / printing it to the screen.

    Thread Starter Kenneth Feldman

    (@kenneth-feldman)

    Thanks — yeah, the isbn is just printing to the page.

    But this is a great start — will run it by a friend who speaks PHP better that I do!

    Thread Starter Kenneth Feldman

    (@kenneth-feldman)

    Okay, super simple fix:

    get_field, instead of the_field — and added echo statement:

    <?php
    $this_tag = get_field('isbn_number');
    echo do_shortcode( '[events_list tag="'.$this_tag.'"]');
    ?>

    Nice, thanks for sharing – it may help someone else.

    Thread Starter Kenneth Feldman

    (@kenneth-feldman)

    Thanks for your help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘PHP Template Code for Events List’ is closed to new replies.