Why not utilize two hooks, one before post saved and one after post saved?
content_save_pre : Function attached with this hook will remove image from content and store it in session/transient.
save_post : With this hook you will have id of post. Function attached with this hook will set featured image for the post with that id and delete session/transient data.
Alternatively, If you want to go with your approach, I think you should use post_name
, instead of guid
, to retrieve post id from database.
Related Posts:
- Add action hook conditionally – only when home.php in use
- How can I tell if I’m on a login page? [duplicate]
- How to hook into the quick edit action?
- WooCommerce add_action hook results in 500 error
- Accepted arguments value in hook functions
- Which action hook to use for function?
- Modify a function without editing template
- Don’t delete a page if it holds users
- Which action does wp_update_user triggers?
- How can I get my Script to work on the Login page?
- Trigger a custom function when option are saved in admin area
- jQuery does not work
- Override the WordPress core function wp_referer_field
- Is there a way to prevent a function/method from being called outside a specific hook?
- Adding code before post title with the_title produces weird results
- Add back in child theme what the parent theme removed with remove_action
- Changing where my author box is printed
- Insert Content Before div#main from the functions.php File
- Replace admin header logo with an image
- Does hook have an effect on increasing the page load?
- Save_post – Warning: Cannot modify header information
- What is the earliest Hook a Script can use?
- How Do I Unhook This Parent Theme Function?
- WordPress hooks to call a function inside a construct
- delete_term is not working properly with add_action()
- remove_action on after_setup_theme not working from child theme
- Issues with title-tag and document_title_parts
- Trying to use add_action and do_action with parameters
- Is there a hook or function I can use to display all theme files being used on a current page?
- add_action in a function, is it possible?
- Using a private method as an action callback from within a class
- Implementing DNS Prefetching with WordPress
- In WooCommerce I need to modify the thankyou.php page [closed]
- Why get_header() or get_footer() does not run twice if called in the same php file?
- Edit the_content function
- How to override WordPress registration and insert an auto-generated username?
- Set default options for inserting media
- Change parent theme file function in child themes functions.php
- gform_after_submission content appears immediately after , not in post body [closed]
- Make WordPress size and name images for Retina.js
- Pinterest Integration Using functions.php
- Allowing SVG uploads in media uploader without plug-in
- Unable to get_the_content(); of a post in WordPress via AJAX
- how to change link of some wordpress pages
- Gravity Forms field entries into wp_query loop [closed]
- Proper way of using functions in action hook?
- Get current page_id before loop, in functions.php
- How to properly add function called by action-hooked function to functions.php?
- Inserting a functions output after the content
- How do I add Bootstrap and LESS to my migrated WordPress site?
- Passing values from a widget to a function within a plugin
- Calling plugin function inside custom plugin for onclick event
- Is there an alternative to get_template_directory_uri()?
- Replace a menu with widget or a custom template file programmatically
- Wait a result before enqueue
- Modify custom field input data before creating a new post
- Footer disappears when using the_content ( )
- Multiple Loops Meta Data
- Get User Login Data (date, time… )
- Function added using `add_action()` not being called
- Why does re-using this function not work? [closed]
- What is the text that appears beside the page titles in the list of pages in the WP admin?
- Two functions with different arguments and add_actions, but identical code
- How to edit the Tags within the image file URLs?
- I can’t seem to install Font Awesome locally [closed]
- Plugin Development – Functions or Hooks?
- Auto log in hook is requiring a page refresh
- problem loading stylesheets to wp_head dynamically
- WordPress redirect redirecting too many times or not at all
- Possible to hook into Media Library preview File column and use a custom image?
- How to properly refresh page after form action?
- WordPress wraps span tags into p tags
- Use add_action within template
- New checkbox in custom widget isn’t saving data
- Why I can’t load my JavaScripts using an hook inside my functions.php file?
- Add content after get_header
- is_home() not working in functions.php file
- template_redirect action only firing if logged in
- Filter for replacing the WP_query object for a given category
- Using get_terms for custom taxonomy in functions.php
- Issue passing action class to nested function. Admin Columns
- The function called on the wp head hook becomes null
- Populate acf-field, depending on block name
- post value to function with Ajax and jQuery
- Use action, filter, or hook to append HTML to WordPress plugin function
- Calling hooks in functions
- use add_action in a shortcode (gravity form – WordPress)
- wp_footer hook causing text to show on bottom of page
- How to add custom column into custom post, when field is select
- True parameter but jquery register in header and not in the footer with wp_register_script
- Sending Messages Back to the Template After Processing?
- previous_post_link inside of a function?
- Problem in outputting shortcode
- Do something when user creates post (that’s pending)
- How can I append and prepend something to all post hyperlinks without using ::before or ::after? PHP hook solution?
- Integrating custom API for post content into Admin interface & Public Website [closed]
- add variable to actions/functions across different files (woocommerce)
- Get category of post inside save_post hook
- Log in and out using custom pages, no logout confirmation and redirects for logging in and out 2023
- Copy and Modified WooCommerce function is_coupon_valid [closed]