WordPress.org

Forums

Front-end Editor
[resolved] Editable Content With Custom Post Types (11 posts)

  1. C. Spencer Beggs
    Member
    Posted 4 years ago #

    I have been working on a project with your inline editing plugin, which is very slick. In a previous release, you said that you supported custom post types. I have registered a new post type called "Deals" but I am not getting the proper markup for the editor when I output text with the_title(), etc. It just outputs regular text without the special <input> markup you JavaScript uses. Interestingly, editable_meta_data() works with custom post types.

    Do I have to tell my post type to support front-end editor?

    Thanks for your help.

  2. scribu
    Member
    Plugin Author

    Posted 4 years ago #

    If you're able to edit them in the backend, you should be able to edit them on the front-end as well.

    Please paste your CPT definition code.

  3. C. Spencer Beggs
    Member
    Posted 4 years ago #

    Here's the code. I am trying to make a table that can be edited:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    On the live page the cell with content outputted by the_title() and the_terms() cannot be edited, however, the content output with editable_post_meta() can be.

    Thanks for your help.

  4. scribu
    Member
    Plugin Author

    Posted 4 years ago #

    Ok, but I meant the register_post_type( ... ) code.

    If you don't have something like that, add the following code after the code you just posted and paste the results:

    <pre>
    <?php print_r( get_post_type_object( 'deal' ) ); ?>
    </pre>
  5. C. Spencer Beggs
    Member
    Posted 4 years ago #

    Ah, sorry for the confusion. Here is the code from functions.php:
    [Code moderated as per the Forum Rules. Please use the pastebin]

  6. C. Spencer Beggs
    Member
    Posted 4 years ago #

    Sorry about that. Here is the code to initialize the custom post type: http://pastebin.com/n5iazLwM

    Here is the output of your request: http://pastebin.com/TzLv2KB1

  7. scribu
    Member
    Plugin Author

    Posted 4 years ago #

    I've added that code to my local install and it works fine.

    Try disabling all other plugins. Then, try swithching to the default theme.

  8. C. Spencer Beggs
    Member
    Posted 4 years ago #

    Hi, scribu,

    I have tinkered around with this. I tried deactivating all other plugins and then registering the same post type in the custom theme, but I am still unable to edit the title, or any of the custom taxonomy fields when I display the custom post_types. I tried this in the default theme.

    Am I calling back the fields imporperly?

    <?php the_title(); ?>
    <?php the_terms($post->ID, 'industry'); ?>
    <?php the_terms($post->ID, 'source'); ?>
    <?php the_terms($post->ID, 'location'); ?>

    the_title(); call is editable when I am looking at it inside the regular loop. The only think I can think is that something is going awry when I register the custom post type. I am using the 'capability_type' => 'post' argument. Should I be listing something else in the 'capabilities' array?

    Thank you again for your help. Oh, and thank you for catching that bug about evaluating custom fields with 0 values. That was killing me ;)

  9. scribu
    Member
    Plugin Author

    Posted 4 years ago #

    All those fields will only be editable if you're in The Loop.

    Specifically, in_the_loop() has to return true.

  10. C. Spencer Beggs
    Member
    Posted 4 years ago #

    Bingo, that seems to be the issue. I am calling a custom WP_Query:

    $args = array(
        'post_type' => 'deal',
        'post_status' => 'publish',
        'orderby' => 'date'
    );
        $deals = new WP_Query($args);
        if ($deals->have_posts()) :
        while ($deals->have_posts()) :
        $deals->the_post();

    The fields aren't edible when I do just that. It looks like WordPress does not consider me to be in the loop, i.e, (in_the_loop() returns false. Luckily, I can manually adjust this with:

    <?php $wp_query->in_the_loop = true; ?>

    Thanks for helping me troubleshoot.

  11. scribu
    Member
    Plugin Author

    Posted 4 years ago #

    Glad to hear you figured it out.

    I have to make that check in order to prevent titles in menus from being editable etc.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Front-end Editor
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic