0

The company I work for has 300+ products on their website. I was able to grab all the published product post URLs on the site, because the permalink shared a common format:

https://domain.com/product/[product-name]

but I was hoping that I can also get the URLs for the post editor for each item.

URL is

https://domain.com/wp=admin/post.php?post=####&action=edit

Is this possible? If so, how? When I tried searching this is the only thing I know that relates to what I'm trying to do but I'm completely unsure because it only gets 1 link not multiple.

1 Answer 1

0

Yes you can have all the editor links for your products. Just run a normal query for the custom post type, in this case seems like the custom post type is "product", but you should search for the custom post type name to run the query. The query will look like this:

$args = array(
    'post_type' => 'product',
    // Put more arguments if you need to
);

$query = new WP_Query($args);

if($query->have_posts()){
    while($query->have_posts()) {
        $query->the_post();
        $post_id = get_the_id();
        //This will print every editor link for your products
        echo "https://domain.com/wp=admin/post.php?post=". $post_id . "&action=edit";

        // You can also use the function get_edit_post_link in here
        //like this: get_edit_post_link( $post_id );
    }
}

I don't know how you want to use the editor links, but this is basically what you need to do to get them, then you can store them in an array or echo them or whatever you want.

2
  • Thank you for this. Where should I put this code? I actually use the Managewp plugin for things like this but for some reason I'm not able to install this plugin, so I'm looking for other options. Should I install another plugin or is there another place where I can put this?
    – Aurora A
    Oct 4, 2021 at 17:12
  • @AuroraA It depends, you don't specify on your question what you want to do with the links, so, I can't tell you where to put it. This is only sample code that will print the urls you need in the front end if you put it in the single.php or the functons.php files.
    – Laloptk
    Oct 4, 2021 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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