Turns out the answer was simply to use url_to_postid
like this:
$keyword = get_post_meta( url_to_postid( "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] ), '_wpg_def_keyword', true );
Works perfectly even from init
.
Related Posts:
- Is there a way to send HTML formatted emails with WordPress’ wp_mail() function?
- Why do some hooks not work inside class context?
- How many times can I hook into the same action?
- Action hook for custom tax edit
- Is there a limit to hook priority?
- Is there a hook before the user is authenticated?
- Auto-retrieve YouTube Image for Thumbnail?
- Do WordPress Core Filenames Work as Hooks?
- switch_to_blog(): Load textdomain
- How to check if which hook triggered the call to a function?
- How do I flush the rules after saving settings using the Settings API?
- Run javascript code after wp_login hook?
- What is the action hook for save media-form on gallery tab?
- Is it possible to save/modify a post without calling the “save_post” action hook?
- Redirect logged in users if they are on a specific page
- Generating robots.txt dynamically
- Hooks are not executing
- after login that will redirect user role into a page
- Rest API Hook When Post Is Requested
- Best possible way to get all options
- Access post meta just after publishing
- wordpress custom modules/widget areas on the page? can i make my own?
- How to add hook to the_title() and get_the_title()
- hook to get (and change) the search string before processing
- Add custom URLs to WordPress’s XML sitemap
- How to override languages files in wp-content/languages/themes with child theme
- Hooking after get_header()
- How to get post ID in post_updated action hook?
- How can I set status=’publish’ for all featured images?
- Run add_action hook if condition
- Gutenberg gallery hook errors
- How to send data from a form created by a plugin to an external API?
- How to get all functions with priority ‘1’ attached to hook ‘wp_head’
- How to change the location of admin notice in html without using Javascript?
- Why doesn’t wp_enqueue_script() work when including a JavaScript file with TEMPLATEPATH?
- What are the differences between comment_form_logged_in_after and comment_form_after_fields?
- Detect change to user_meta and retrieve old and new values
- WordPress action and filter hooks runs asynchronously?
- Prevent attachment from being deleted
- Featured Image Action Hook
- How to find a callback attached to a bbpress hook?
- Event Calendar using insert_post_data after save_post and insert_post after post_transition draft_to_schedule
- How to extend custom (non-core) blocks?
- Hooking into the init action will fire it too frequently?
- Implement Hooks Using Array
- What hook is used to display the admin_bar on the front end?
- Is there a JavaScript equivalent of get_post_field?
- Adding a hook to the default (page.php) template
- Add action hook into wp_localize_script
- Send along login credentials with comment content
- Conditional for autosave or auto draft?
- Using delete_attachment to prevent an attachment not working
- How does do_action( ) works actually?
- Redirecting from login
- How to use a 3rd party library to send emails?
- Giving the_excerpt in the place of the_content?
- Hook to init or call explicitly within functions.php
- How to add content to the end of a page with a hook?
- WordPress’s “Text” Format
- Alternative to new_to_publish Hook for Custom Statuses
- run script on publish
- Calling add_action on a filter hook?
- Remove Header and Footer if user is not logged on
- How to use embed_content hook?
- What is deprecated_argument_run meant to do exactly?
- How do I run an action after a featured image has been selected in the Gutenberg editor?
- How to run a function after wp() in the wp-blog-header.php file?
- WordPress cronjob get scheduled but function does not run
- How to add a HTML element in ADMIN edit post window?
- wp query add array by if condition
- call php file from form and use wp functions
- Gravity Forms | Form Object is NULL [closed]
- Change status of page after an event (Looking for best practice advice)
- wp_insert_post hook for a wordpress plugin
- Add action save post when create and publish
- Hooks for Start/End of Batch Plugin Updates in wordpress
- How to load another post if condition is true
- Session management issues with WordPRess 404 Error page
- Template_redirect works, but headers aren’t sent when checking via cURL
- Struggling with plugin dev basics: add_action
- RTrouble passing arguments to action
- delete_user hook failed
- Which things should be called with `after_setup_theme`?
- Changing header logo href for the checkout page
- Prefixing widget_posts_args Hook
- Can’t get ID of post that relates to the comment
- Updating user meta data from external link, user not logged in
- Remove lines from RSS Feed
- Is there a hook that triggers when grant secondary user role in WordPress?
- How to create callback function which returns all posts with specific data?
- How can I insert custom html code inside a div dynamically?
- How WordPress understands what do with the (all) key in the $wp_filter array? [duplicate]
- WP-Automatic to run publish hooks
- How to work with hooks and Posts to posts plugin?
- When is get_currentuserinfo() needed?
- disable publish button until condition is not met
- Hide post completely and still reach it via cURL
- Problem in register activation hook and Copying folder
- Why does hook priority affects admin menu permission error?
- add_action failed to display function by a plugin