0

Here is the PHP that I have which i am trying to change:

global $current_user, $post, $product;

?>     
 <?php if ( $post->post_author == get_current_user_id() ) { ?>
        <div class="wpproductedit">     
            <p class="wpproducteditbutton"><a href="http://blah.com/private/products">EDIT</a></p>
         </div>
 <?php } ?> 

Here, the button only takes the user (author of the product) to product page which then they have to find the product they want to edit.

So any product edit page will have the following URL:

http://blah.com/shop/product-x/edit

http://blah.com/shop/product-y/edit

As you can see, only the product name changes.

In summary, I am trying to edit the "Edit" link so that it will be like the following and picks up the product name automatically.

http://blah.com/shop/"ANYPRODUCT"/edit
1

If I understand your question correctly, I think what you are looking for is edit_post_link();

To use it just insert <?php edit_post_link(); ?> into your theme. This will output a edit link leading to the current page/posts editor.

Update after rewrite of question:

You can replace your link with the following to include the posts slug in the url.

<a href="http://blah.com/shop/<?php echo $post->post_name; ?>/edit">

You might want to look into also replacing the hardcoded link http://blah.com/shop/ with a more generic like home_url();.

  • Hey sorry to bother you again. So, I realized that it was actually (blah.com/shop/"Category"/"Product"/edit). So I added the following: <a href="blah.com/shop/<?php echo $product->get_categories; ?>/<?php echo $post->post_name; ?>/edit">EDIT</a> But the output is only blah.com/shop//productname/edit. It looks like "get_categories" are not pulling the category name properly. Any suggestions? Thanks! – Steve Kim Mar 20 '15 at 10:33
  • 1
    Not sure what is in your $product global and thus $product->get_categories. Try doing a var_dump($products); to see whats in it or something. You might be better of opening a new question regarding that part, these comments aren't meant/suited to be for new questions/answers. – jzatt Mar 20 '15 at 13:31

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.