Untitled UI logotext
Solutions
WebsitesEcommerceMobile AppsWeb AppsProduction Support & Maintenance
Our work
Company
About usBlogPodcastContact us
Book a free consultation

Getting and updating a wordpress post from permalink

Olivia Rhye

We've been working on a plugin and we needed to get a wordpress page from a given permalink. This is actually done pretty easily since there is a function wordpress uses deep in their system.


$post_id = url_to_postid($permalink);

This will give you the post_id which you will able to use to retrieve the post object.


$post = get_post($post_id);

Now that we have the object its pretty simple to manipulate it.


$post->post_content = $new_page_content;
wp_update_post( $post );

So all together:


$post_id = url_to_postid($permalink);
$post = get_post($post_id);
$post->post_content = $new_page_content;
wp_update_post( $post );

Ready to start a project?

Book a free consultation
Untitled UI logotext
Our work
About us
Blog
Careers
Submit a ticket
Agency Partnerships
Contact
© 2024 fjorge. All rights reserved.
Privacy