You get the exact unchanged value with:
$event_id = filter_input( INPUT_GET, 'event_post_id', FILTER_VALIDATE_INT );
Here I added the validation filter directly, but you can even move that to separate code for more complex cases.
WordPress’ query variable handling is for cases in which you want to allow changes to the values before they reach your code.
“Best practice” is quite a loaded expression, that’s why we often shy away from that label. 🙂
Write code you and someone else (=future you) can maintain and understand.
If there is a fast and readable PHP way, use that. filter_input()
gives you the variable as sent by the client, and no matter what WP does, it will always stay the same. The super globals $_GET
, $_POST
and so on are writable, you can’t trust them.
Related Posts:
- Difference Between Filter and Action Hooks?
- Explanation of the “posts_join” and “posts_fields” filter hooks?
- How do you use the plugin boilerplate loader class to hook actions and filters?
- How do I Make a Theme “plugin-ready”?
- How to modify post content before writing to database?
- What’s the difference between hooks, filters and actions? [duplicate]
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- Is it possible to create an action hook using do_action() within add_action()?
- Hook for post permalink update
- Dynamically Override Fancy Title
- Define a function outside a class and call the function using action or filter hook
- Synchronize Custom post type tags to WordPress default posts tags
- Woocommerce – Hide a Column in Cart Table
- WordPress after content Hook & external template part
- Namespaced action and filter tags
- get_current_screen() return null
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- WordPress custom taxonomy check box to dropdown
- How to get all queries’s results after they have executed?
- Remove an action by extending class and replacing it
- hook filter after the_content on a specific page
- Bind a function with its own argument to show something dynamically after every content
- Hook add_attachment error
- Call to undefined function is_home() or any conditional tags
- WooCommerce change Tax Class programmatically when Recalculating an existing Order [closed]
- Update variable value via add_filter
- Configure WordPress to Generate Scheme-less Relative URLs
- How to find list of all functions bind to a particular hook from my plugin?
- apply_filters() and call_user_func() to define and call a function outside a class
- Limit get_next_post to posts from the same author
- Any way, hook to add content right before the “read more” link?
- WordPress Plugin Boilerplate – add actions and/or filters based on user’s role
- Add_action not calling callback function
- How do I replace title with my plugin?
- Apply function on all action hooks?
- Ninja Forms: Front-End Forms, Post ID?
- Add child pages to submenu automatically
- After plugin activation hook
- How to replace default comments with custom HTML?
- Odd map_meta_cap $args on post edit — sometimes integer, sometimes string
- Trying to get class to instantiate ONCE (or, “why do I keep punching myself in the head?”)
- How can I create a custom plugin that allows anonymous users to signup without registering?
- Is there an admin hook that will let me read GET variable before it’s too late to set the header Location
- Why enqueue styles on hook?
- What’s the hook for filtering every texts of site?
- Associate multiple email addresses with the same user account, so they can log in with either
- Run command “composer install” when activating wordpress plugin
- Add a check box in Menu Settings
- Custom filter not working
- hook update_option/updated_option empty $old_value and $value
- Make wordpress join default user metas with a column from another table while displaying the wp_users table on the users screen
- Hide one specific woocoomerce product
- Gravity Forms Anchor only on Front Page?
- Can I Hook Into the TinyMCE Insert/Edit Link Button to Use Shortlink For Post?
- Include HTML (Bootstrap Modal Box) with a plugin into my header
- Using init hook for register_taxonomy is causing invalid_taxonomy in wp_insert_term()
- Ajax +wordpress onClick link redirect to new page and create html content
- WP_NAV_MENU filter targets all menus
- How to replace settings in WordPress plugin from a theme
- Redirect returning users to a certain page?
- Adding filter to the title without affecting the menu title
- Restrict certain actions to plugin-specific admin menu pages only
- How to validate inputs with filter in register_setting callback
- How do i remove the title from a specific page
- Can / should a widget plugin define its own Widget Area?
- How to get changed post title in my custom plug-in which fires when ‘save_post’ is called?
- Is there an action_filter hook to add content before the post title?
- Adding tables to dashboard pages programmatically?
- Can I attach a plugin via my add_filter callback contents?
- Creating posts with links from a txt file
- Set the payment processor callbacks to a plugin
- Add hook after content without formatting
- Action / Hook when a new plugin is added
- Getting Post ID at “stylesheet” and “template” hooks
- add_filter postbox_classes multiple post types
- How to enhance a self developed plugin by its own plugin architecture
- Trigger function on Remove block or add new block in Gutenberg JavaScript
- How to update global variables in plugin activation callback?
- Woocommerce get_term_by() in transition_post_status hook doesn’t works
- Add two button to page and post admin to redirect to : add new & list of (posts – pages) just after saving post or page
- Override category archive page title (not the head title)
- `registration_errors` filter doesn’t seem to be called
- How to grab data after wp user search is complete
- Override woocommerce loop-start.php from theme using plugin?
- Is there any way to get post meta from publish_post hook?
- Why does do_action pass a blank string as the first parameter if no $arg is set?
- Add a custom submenu under submenu in a Custom WordPress Plugin
- using filter and hook inside class
- How do I ensure I can loop through every enqueued script and CSS?
- Hook for validating and rejecting frontend image upload
- Does hooking into a plugin action / filter override the plugin’s function for that hook?
- Nested Hooks with do_action for performance reasons – safe/necessary?
- Problem in plugin debuging in wordpress
- OOP development and hooks
- Plugin Development – Call to undefined function comment_exists()
- Redirect theme directory to plugin theme directory
- remove different admin menu for specific users
- WordPress Reset password Strength set to medium
- Change Front page displays settings conditionally when user is online
- login_message filter not working