0

I'm new to WordPress development, so apologies if this is a simple matter.

I have created several custom post types and I want to let users add/edit content from the front end. I thought it's easy. Just call wp_editor() with your post ID and it will know which type of controls to display (I am using Advanced Custom Fields), but it seems like wp_editor() displays a simple text box for each post, regardless of the post type. I know there are heaps of plug-ins that claim they can let users edit posts from the front-end, but I much prefer to have the built-in editor appear on the front end. Is there another function I can call in place of wp_editor() that I am missing?

  • @Sally That's an interesting one... Another way to do what I want to achieve. So, you reckon there is no way to get WordPress to execute its editor code for me? – iMan Biglari Mar 8 '18 at 6:45
  • Sorry, what do you mean by that? Is the editor not displaying? Or do you want to disable one or more of its features (e.g. the Add Media button)? – Sally CJ Mar 8 '18 at 6:53
  • 1
    Yes, if you don't want to use a plugin, then you'd have to manually create the form (for editing the ACF fields on the front-end). wp_editor() will just output a textarea with TinyMCE and Quicktags support, and not a form where you can edit custom fields... – Sally CJ Mar 8 '18 at 7:30
  • 1
    @Sally If you post your first comment as answer I'll accept. It was easier than I thought :D – iMan Biglari Mar 8 '18 at 20:25
1

wp_editor() displays a simple text box for each post

It's not actually a "simple text box" =), because wp_editor() allows you to convert/turn textarea to a rich-text/WYSIWYG editor using the TinyMCE library.

I want to let users add/edit content from the front end

Because you're using Advanced Custom Fields (ACF), then there's an easy way to do that, which is basically by using acf_form(). And based on the example on this page, here's a sample Page template you can use with the Twenty Seventeen theme:

<?php
/**
 *  Template Name: ACF Create Post
 */

acf_form_head();

get_header(); ?>

<div class="wrap">
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">

            <?php while ( have_posts() ) : the_post(); ?>
            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                <header class="entry-header" style="width: 100%;">
                    <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
                    <?php twentyseventeen_edit_link( get_the_ID() ); ?>
                </header><!-- .entry-header -->
                <div class="entry-content" style="width: 100%;">
                    <?php
                        the_content();

                        acf_form( array(
                            'post_id'      => 'new_post',
                            'field_groups' => array( 1858 ),
                            'submit_value' => 'Create Post',
                        ) );
                    ?>
                </div><!-- .entry-content -->
            </article><!-- #post-## -->
            <?php endwhile; ?>

        </main><!-- #main -->
    </div><!-- #primary -->
</div><!-- .wrap -->

<?php get_footer();

Hope that helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.