In my last question, I asked How to build a post and comment editing form in a page?.

But in order to edit the custom post type (called Question) I have to reference the edit page and the ID of the custom post type.

I created a file called edit-question.php (located in the theme's folder).

And created a page called Edit Question in the Wordpress admin panel (and assigned the template file edit-question.php to it).

And placed the following code to display the edit link right before the loops ends (loop-question.php):

    <?php endif; // This was the if statement that broke the loop into three parts based on categories. ?>

    <?php if ($post->post_author = $current_user->ID) : ?>
        <a href="<?php bloginfo('url'); ?>/edit-question.php?qpost_id=<?php $post->ID ?>">Edit!</a>
    <?php endif; ?>

<?php endwhile; // End the loop. Whew. ?>

When I click the Edit! link I get the following in my URL bar: http://localhost/qaf/edit-question.php?qpost_id=.

Looking at the default edit link of Wordpress looks like this:


I think I have to make something similar except the action=edit part (not very sure).

What's the best way of doing this?

  • 2
    You need to echo the $post->ID so just add echo before it. And you don't need the edit action that is for the admin side and not the frontend – Bainternet Mar 8 '11 at 9:20
  • or simply use wordpress function <?php the_ID() ?> – galvakojis Mar 18 '19 at 16:06

Regularly You have this:

<?php edit_post_link( $link, $before, $after, $id ); ?> 

In this example use "echo"

<?php echo $post->ID ?>">


<?php $post->ID ?>">
| improve this answer | |

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.