I made a custom post type called “Gallery” that uses the ACF Pro repeater field. I want to be able to insert a Gallery into the middle of a blog post using the TinyMCE WordPress editor. How do I do this? Do I need to turn it into a plugin? Do I need to make a button for it?
I don’t know if I’m even barking up the right tree here, but could someone give me a clue?
It’s something that you can do, but will take a lot of work as most of what you want to do is not documented and there are very few examples that exist.
Alternately you could create a custom shortcode that could be inserted into the gallery where the shortcode gets the values of the repeater and inserts a gallery into the desired location when displaying the field. https://codex.wordpress.org/Shortcode_API
Okay so I think the shortcode thing is probably in the right direction.
Here’s what I’m trying right now. I created a custom post type called “Galleries”. The only field group for it is the repeater that I mentioned earlier.
In order to insert a gallery in the middle of a blog post, my plan is to have a shortcode that injects one post (the custom Gallery Post ) into another.
I just trie ddoing this using this plugin: https://wordpress.org/plugins/post-content-shortcodes/
But it only seems to work for injecting The Content (from the WYSIWYG editor) and won’t pull in anything else from the php loop etc.
Any way of doing that? Or am I going to make my own shortcode etc using the codex?
Okay, it does indeed work with this plugin! Except for some reason my repeater plugin is saying that it’s not finding any rows. My loop starts like this
<section class="grid-content"> <div class="gridGallery"> <?php // check if the repeater field has rows of data if( have_rows('card') ): // loop through the rows of data while ( have_rows('card') ) : the_row();
And then I have this:
else : ?> <p>no rows found</p> <?php // no rows found endif;
And it seems that instead of pushing out all my gallery images it’s detecting zero rows and going to the else statement. I’m sure there’s an easy fix here I’m missing but I can’t catch it exactly…
That’s the main reason for suggesting a custom shortcode because in order to get the fields from the right post you need to tell ACF what post to get them from.
The plugin that you mentioned does say to do exactly what you’re trying to do. I don’t know anything about that plugin, but since the instructions tell you to do what you’re doing I would ask over there.
I asked over at the support forums and found an answer! I just had to wrap them in an additional containing loop to the template. Full answer can be found here in case any future person searching the forums needs it:
<?php /* Template Name: Your Custom Template Name */ ?> <?php while ( have_posts() ) : the_post(); ?> <div>Your custom content, including any template tags you want to use like <?php the_post_thumbnail(); ?></div> <?php endwhile; ?>
The topic ‘How to turn custom fields into something I can insert into WYSIWYG editor?’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!