• Resolved traypup

    (@traypup)


    Hi there,
    I’ve tried a few different ways and I’m close, but my syntax, I think, is throwing things off. Can someone help me get my code right?

    I put together a FAQ page using Advanced Custom Fields. That bit is working great. Now I want to add in C-o-M so the user can click the titles and show the answers.

    I had this:

    [expand title="<?php the_sub_field('question_title') ?>"]
    <p><?php the_sub_field('question_answer') ?></p>[/expand]')

    and it showed the question titles and answers, but also the brackets and “expand” code, so I realized I needed to call the shortcode first and did this:

    <?php echo do_shortcode('[expand title="<?php the_sub_field('question_title') ?>"]
    <p><?php the_sub_field('question_answer') ?></p>[/expand]') ?>

    And the page is showing the error
    Parse error: syntax error, unexpected T_STRING

    Any suggestions on how to fix?
    Thank you!

    https://www.ads-software.com/plugins/jquery-collapse-o-matic/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Baden

    (@baden03)

    you almost have it. Try:

    <?php echo do_shortcode('[expand title="'.the_sub_field('question_title').'"]'.the_sub_field('question_answer').'[/expand]'); ?>

    Please let us know if this works for you.

    Thread Starter traypup

    (@traypup)

    Ok, cool, the error message isn’t coming up any more, but I’m still not getting the collapsing functionality. All of the Qs and As are just laid out on the page. But the arrows are clickable and change back and forth between pointing up and down! ??

    Plugin Author Baden

    (@baden03)

    under the plugin option page (Dashboard > Settings > Collapse-O-Matic) check and make sure that the check box for “Shortcode Loads Scripts” is UNchecked.

    For further assistance you will need to share a link so we can trouble shoot further.

    Thread Starter traypup

    (@traypup)

    It is unchecked.

    Can I email you a link and login? I have the site hidden at the moment since it’s in development. Thank you!

    Plugin Author Baden

    (@baden03)

    yes. just be sure to include a link to this thread and shoot it to us info [at] twinpictures [dot] de

    Thread Starter traypup

    (@traypup)

    thank you! emails will come from websmith [at] eeep [dot] com

    Plugin Author Baden

    (@baden03)

    We took a look, and the_sub_field('question_answer') is returning NULL.

    var_dump(the_sub_field('question_answer'));

    Please verify that the_sub_field('question_answer') is the correct way to call the faq answer.

    Thread Starter traypup

    (@traypup)

    Interesting. That is the correct field name. I took a screen shot of the ACF page that shows the fieldnames: https://www.evernote.com/shard/s30/sh/9016444c-eaf8-44dc-80e9-a8058c0f2491/1ad47ac4cd63bf1438ececb6d026bb49

    If you look at the FAQ page (https://eeep.com/crl/faq-for-physicians/), you’ll see that the contents of that field show up in the page…so I’m not sure how it returns NULL. (Unless I’m not understanding what you’re saying!)

    Thread Starter traypup

    (@traypup)

    Do you have any other ideas on this issue?

    Thread Starter traypup

    (@traypup)

    It’s fixed. I prevailed upon a colleague to take a look. Here’s what he did:

    Just made a couple of simple changes. You just needed to change “the_sub_field” to “get_sub_field”. The “the_” call will display the information whereas “get_” stores a value which works with the plugin because it’s creating a link from the title.

    I’ve left the title as the_field – however, if you change this to “get_sub_field” it will create the title as a link and move the arrow to the left of the title. It’s up to you I don’t think it effects usability at all.

    I simply deleted

    <?php

    //var_dump(the_sub_field(‘question_answer’)); //returns null

    echo do_shortcode(‘[expand title=”‘.the_sub_field(‘question_title’).'”]’.the_sub_field(‘question_answer’).'[/expand]’);

    ?>

    and replaced it with

    <?php

    //var_dump(the_sub_field(‘question_answer’)); //returns null
    $title = the_sub_field(‘question_title’);
    $answer = get_sub_field(‘question_answer’);

    echo do_shortcode(‘[expand title=”‘ . $title . ‘”]’ . $answer . ‘[/expand]’);

    ?>

    Plugin Author Baden

    (@baden03)

    glad you got it working

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘putting the shortcode into my template’ is closed to new replies.