Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    Could you show me the code that you’re using? Also, is the code in the normal post editor or in a visual builder of some kind?

    I’ve tested [field url] and they’re working on my end; so, I’ll try to find out what is specific about your use case – for example, the surrounding context (is it in a loop, in an HTML attribute href or generated from [link], etc.)

    Thread Starter mhairilongmuir

    (@mhairilongmuir)

    Hi,

    Thank you for your reply.

    The code is in the normal post editor.

    Yes, it’s in a loop.

    You can see that the ‘view’ button inside the accordions isn’t going anywhere: https://www.etextbooks.ac.uk/dissertations/chapter-1-what-is-research-and-why-do-it/

    Here is the code that I’ve used:

    <h3>Chapter 1 resources</h3>
    Click on the section to expand it
    
    [insert_php]
    $str='
    [loop type="interaction" taxonomy="chapter" term="1" taxonomy_2="interaction-media-types" term_2="images" compare="and"][field title][/loop]
    ';
    if(checkshortcodeoutput($str)){
    echo do_shortcode('
    [toggle title_open="Images" title_closed="Images" hide="yes" border="yes" style="default" excerpt_length="0" read_more_text="Read More" read_less_text="Read Less" include_excerpt_html="no"]
    [raw]
    [block class="table-of-interactions"]
    [loop type="interaction" taxonomy="chapter" term="1" taxonomy_2="interaction-media-types" term_2="images" compare="and"]
    [fourcol_three]
    <h4 style="margin-bottom: 10px;">[field title]</h4>
    <p style="margin-bottom: 10px;">[field short_description format="true" length="365"]</p>
    <a class="button small" href="[field url]">view</a>
    [/fourcol_three][fourcol_one_last]
    <a style="float: right;" title="[image-title]" href="[field url]">[field image="thumbnail" size="thumbnail"]</a>
    
    [/fourcol_one_last]
    
    <hr />
    
    [/loop]
    [/block]
    [/raw]
    [/toggle]
    ');
    }
    [/insert_php]
    
    [insert_php]
    $str='
    [loop type="interaction" taxonomy="chapter" term="1" taxonomy_2="interaction-media-types" term_2="audio" compare="and"][field title][/loop]
    ';
    if(checkshortcodeoutput($str)){
    echo do_shortcode('
    [toggle title_open="Audio" title_closed="Audio" hide="yes" border="yes" style="default" excerpt_length="0" read_more_text="Read More" read_less_text="Read Less" include_excerpt_html="no"]
    [raw]
    [block class="table-of-interactions"]
    [loop type="interaction" taxonomy="chapter" term="1" taxonomy_2="interaction-media-types" term_2="audio" compare="and"]
    [fourcol_three]
    <h4 style="margin-bottom: 10px;">[field title]</h4>
    <p style="margin-bottom: 10px;">[field short_description format="true" length="365"]</p>
    <a class="button small" href="[field url]">view</a>
    [/fourcol_three][fourcol_one_last]
    <a style="float: right;" title="[image-title]" href="[field url]">[field image="thumbnail" size="thumbnail"]</a>
    
    [/fourcol_one_last]
    
    <hr />
    
    [/loop]
    [/block]
    [/raw]
    [/toggle]
    ');
    }
    [/insert_php]
    
    [insert_php]
    $str='
    [loop type="interaction" taxonomy="chapter" term="1" taxonomy_2="interaction-media-types" term_2="videos" compare="and"][field title][/loop]
    ';
    if(checkshortcodeoutput($str)){
    echo do_shortcode('
    [toggle title_open="Video" title_closed="Video" hide="yes" border="yes" style="default" excerpt_length="0" read_more_text="Read More" read_less_text="Read Less" include_excerpt_html="no"]
    [raw]
    [block class="table-of-interactions"]
    [loop type="interaction" taxonomy="chapter" term="1" taxonomy_2="interaction-media-types" term_2="videos" compare="and"]
    [fourcol_three]
    <h4 style="margin-bottom: 10px;">[field title]</h4>
    <p style="margin-bottom: 10px;">[field short_description format="true" length="365"]</p>
    <a class="button small" href="[field url]">view</a>
    [/fourcol_three][fourcol_one_last]
    <a style="float: right;" title="[image-title]" href="[field url]">[field image="thumbnail" size="thumbnail"]</a>
    [/fourcol_one_last]
    
    <hr />
    
    [/loop]
    [/block]
    [/raw]
    [/toggle]
    ');
    }
    [/insert_php]
    
    [insert_php]
    $str='
    [loop type="interaction" taxonomy="chapter" term="1" taxonomy_2="interaction-media-types" term_2="useful-web-links" compare="and"][field title][/loop]
    ';
    if(checkshortcodeoutput($str)){
    echo do_shortcode('
    [toggle title_open="Useful web links" title_closed="Useful web links" hide="yes" border="yes" style="default" excerpt_length="0" read_more_text="Read More" read_less_text="Read Less" include_excerpt_html="no"]
    [raw]
    [block class="table-of-interactions"]
    [loop type="interaction" taxonomy="chapter" term="1" taxonomy_2="interaction-media-types" term_2="useful-web-links" compare="and"]
    [fourcol_three]
    <h4 style="margin-bottom: 10px;">[field title]</h4>
    <p style="margin-bottom: 10px;">[field short_description format="true" length="365"]</p>
    <a class="button small" href="[field url]">view</a>
    [/fourcol_three][fourcol_one_last]
    <a style="float: right;" title="[image-title]" href="[field url]">[field image="thumbnail" size="thumbnail"]</a>
    [/fourcol_one_last]
    
    <hr />
    
    [/loop]
    [/block]
    [/raw]
    [/toggle]
    ');
    }
    [/insert_php]
    
    [insert_php]
    $str='
    [loop type="interaction" taxonomy="chapter" term="1" taxonomy_2="interaction-media-types" term_2="activities-tools" compare="and"][field title][/loop]
    ';
    if(checkshortcodeoutput($str)){
    echo do_shortcode('
    [toggle title_open="Activities & tools" title_closed="Activities & tools" hide="yes" border="yes" style="default" excerpt_length="0" read_more_text="Read More" read_less_text="Read Less" include_excerpt_html="no"]
    [raw]
    [block class="table-of-interactions"]
    [loop type="interaction" taxonomy="chapter" term="1" taxonomy_2="interaction-media-types" term_2="activities-tools" compare="and"]
    [fourcol_three]
    <h4 style="margin-bottom: 10px;">[field title]</h4>
    <p style="margin-bottom: 10px;">[field short_description format="true" length="365"]</p>
    <a class="button small" href="[field url]">view</a>
    [/fourcol_three][fourcol_one_last]
    <a style="float: right;" title="[image-title]" href="[field url]">[field image="thumbnail" size="thumbnail"]</a>
    [/fourcol_one_last]
    
    <hr />
    
    [/loop]
    [/block]
    [/raw]
    [/toggle]
    ');
    }
    [/insert_php]
    
    <hr />
    
    <h3>Chapter 1 discussion forum</h3>

    And here is the code in the PHP snippet (it makes the accordion only show if there is content inside it – I had someone else write this code)

    add_filter( 'the_content', 'will_bontrager_insert_php', 8 );
    //add_filter('the_content', 'do_shortcode', 11);
    function checkshortcodeoutput($str){
      if(!empty($str)){
    	$output=do_shortcode($str);
    	if(!empty(trim($output)))
    	  return true;
    	else
    	  return false;
      }
    }
    remove_filter( 'the_content', 'wpautop' );
    add_filter( 'the_content', 'wpautop' , 12);

    Thank you for any help, I’m up against a deadline and hoping I can get this sorted without having to redo it with another plugin on every page.

    Cheers ??

    Plugin Author Eliot Akira

    (@miyarakira)

    I see, the code is wrapped and run by PHP, before getting to the post content filter. Can you try changing this line:

    echo do_shortcode('

    ..to..

    echo do_ccs_shortcode('
    Thread Starter mhairilongmuir

    (@mhairilongmuir)

    Hi, thank you for your reply, and sorry for taking so long to get back to you, I work 3 days a week here.

    I’m so so delighted – that worked for me!

    Can you give an explanation what was the problem? Is it likely to suddenly stop working again in the future? (if it is, then I need to re-evaluate how I do it).

    Many thanks – might have saved me a LOT of work ??

    Plugin Author Eliot Akira

    (@miyarakira)

    The reason is that since WordPress 4.2.3, the do_shortcode() function processes shortcodes inside HTML attributes (like href="[field url]") differently. do_ccs_shortcode() was written to get around this, to make it work as before.

    There’s a way to check the existence of a post before running the loop, which can make your code simpler. Something like:

    [loop exists type=interaction taxonomy=chapter term=1 taxonomy_2=interaction-media-types term_2=images compare=and]
    
    [toggle ...][raw][block ...]
    
    [the-loop]
    
    [fourcol_three]...[/fourcol_three]
    [fourcol_one_last]...[/fourcol_one_last]
    <hr />
    
    [/the-loop]
    
    [/block][/raw][/toggle][/loop]

    This would not need the PHP work-around, and would be more reliable.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[field url] not working’ is closed to new replies.