Support

Account

Home Forums General Issues How to trick plugins to think fields are the_content?

Solved

How to trick plugins to think fields are the_content?

  • I’m trying to use Table of Contents + with custom fields.

    At the moment, Table of Contents + only looks at the_content, and looks for header tags. Then, if there’s three or more, it auto creates a table of contents, pulls those header names and anchors, and nicely formats them.

    I’ve began to painfully convert my site into a huge content field into fields and subfields.

    Here’s a perfect example of it not working property:

    http://jeremynative.com/onthissite/listing/sugar-loaf-hill/

    I have Introduction, History one, and History two as custom fields in ACF. Excavation, Artifacts, Burials, and Historic Significance are in the old default content field, thus TOC+ detects them and puts them into the Contents box.

    Is there a way to make it read my new fields and their H2 tags? Really a shame if I have go to back to using one content field.

  • Hi @jeremynative

    I’m afraid this issue is more related to Table of Contents +. It should have a function that processes the content and produces the table of contents. Could you please get in touch with the plugin author to learn how to add the custom fields to that function?

    I hope this makes sense 🙂

  • Hi @james

    I see, maybe we can ignore my mentioning of the plugin. I want to include all of my fields for a layout to be included in the the custom post the_content()

    I tried this, which works and lets my ACF fields work with other plugins, but it repeats hundreds of times. Why is that? Here it is live http://jeremynative.com/onthissite/listing/sugar-loaf-hill/

    function add_acf_content( $content ) { 
    
         if( have_rows('repeater_field_name') ) {
              while( have_rows('repeater_field_name') ): the_row(); 
                 $content .= "<h2>" .  get_sub_field('title_sub_field') . "</h2>";
                 $content .= get_sub_field('sub_field_3'); 
            endwhile; 
        }
    
        return $content;
    }
    
  • Hi @jeremynative

    I’m afraid I can’t see it repeats on your page. I’ve attached a screenshot for your reference.

    Also, I can’t see what’s wrong with your code. I’ve tested it on my installation and it works correctly. Could you please debug the returned data like the following?

    echo "<pre>";
    var_dump( get_field('repeater_field_name') );
    echo "</pre>";

    Thanks 🙂

  • Hi @acf-support

    I foolishly work on my live website, haven’t figured out how to use MAMP for a local environment. What you’re seeing now is the function with this removed:

    $content .= get_sub_field(‘sub_field_3’);

    with only the first $content line, it seems to work okay.

    I’m now trying to research ways to implement this type of function within the single-listing.php (the custom post template).

    That way, I can both create a layout for these posts and also have the content situated within the the_content(), though it seems very difficult to achieve…

  • Hi @jeremynative

    Does the issue is resolved? If not, could you please let me know what’s wrong with it?

    Thanks 🙂

  • I don’t think its possible to fix, it seems to be a limitation with custom fields and the_content sadly.

  • Hi @jeremynative ,

    I’m trying to achieve a similar thing now. I have checked the mentioned page on your website and it seems you got it working at the end.

    Would you mind sharing the approach that worked?

    Big thanks,

    Ondrej

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘How to trick plugins to think fields are the_content?’ is closed to new replies.