$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>urls - Problem creating an edit link for a custom post type|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

urls - Problem creating an edit link for a custom post type

matteradmin9PV0评论

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:

http://localhost/qaf/wp-admin/post.php?post=61&action=edit

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

What's the best way of doing this?

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:

http://localhost/qaf/wp-admin/post.php?post=61&action=edit

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

What's the best way of doing this?

Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Mar 8, 2011 at 6:09 wycwyc 3,90719 gold badges61 silver badges97 bronze badges 2
  • 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 Commented Mar 8, 2011 at 9:20
  • or simply use wordpress function <?php the_ID() ?> – galvakojis Commented Mar 18, 2019 at 16:06
Add a comment  | 

1 Answer 1

Reset to default 2

Regularly You have this:

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

In this example use "echo"

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

Instead:

<?php $post->ID ?>">
Post a comment

comment list (0)

  1. No comments so far