I figured it out, here is the solution for anyone else wondering how to do something like this:
function force_ID($query) {
global $wpdb;
if (substr($_SERVER['REQUEST_URI'],-5) == '.html') {
$post_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name=%s AND post_status="publish"",substr(basename($_SERVER['REQUEST_URI']),0,-5)));
if ($post_id > 0) $query->set('page_id',$post_id);
}
}
add_action('pre_get_posts','force_ID');
In examining the wp-includes/query.php file, I noticed that the object accepts page_id to exclusively select an ID. Using post_id worked for archive post loops, but page_id worked for a single post call.
Related Posts:
- What is the Difference between directly call a function and call a function using add_action?
- WordPress class, using add_action to call member function does not work
- Call to undefined function is_home() or any conditional tags
- Adding tables to dashboard pages programmatically?
- wp_ajax add_action fuction won’t fire on custom jQuery action
- How to add user details to different tables immediately after user registration
- How to filter content for specific content variable
- pre_get_post alter current post id
- mysql_real_escape_string() vs. esc_sql() in WordPress
- load_plugin_textdomain doestn’t work with add_action plugins_loaded
- Show error message after exception handled
- I have 2 plugins using the same wp_login action hook and one is not working
- WordPress function get_the_terms() returns ‘Invalid taxonomy’ error
- Checking for existence of a page by title?
- Valid filenames for add_action’s first parameter
- how to get context information inside my funcion
- Where do I put my add_action(… and add_filter(… and do I need to remove them?
- How dynamic action login_form_{action} is working
- How to modify files inside wp-includes directory in wordpress
- Fatal error: Call to a member function get_page_permastruct() on a non-object
- wp_get_post_terms Order by not working
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- How to get all queries’s results after they have executed?
- Function/Class to list categories with checkboxes
- wp_get_theme Warning: Illegal offset type
- Bug: Post needs to be updated twice when adding action for save_post hook
- Delete data from database using row action
- Why wp_die() doesn’t work with wp_redirect but exit() works
- When does save_post hook fire on post save/update
- Warning: call_user_func_array() expects parameter 1 to be a valid callback
- Print Dashboard submenu name and filename
- Autogenerate a Table of Contents
- Alternative functions for mysql_free_result and mysql_ping in wordpress functions
- how to get the post id in plugin
- A question about add_action()
- WordPress multisite,use same cookies across all website?
- Apply styles to blockquote element with the WYSIWYG editor
- Hook add_attachment error
- unregister_setting() vs delete_option() for plugin update
- How to change WooCommerce loop product title HTML output in single product page and archive page
- How to output functions from plugin inside theme
- wp_schedule_event is registered but function isn’t running
- How to find list of all functions bind to a particular hook from my plugin?
- 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
- Overwriting a plugin function
- wordpress automatic update does not run
- Writing editor content to a file
- Using init hook for register_taxonomy is causing invalid_taxonomy in wp_insert_term()
- Remove Permalink Meta Box not working?
- How Can I Add Code To A Preexisting Function Without Editing it
- using admin functions on frontend
- Javascript Function Called Too Early in PHP Script
- Modify code for functions.php with specific twitter user url and hashtags
- can’t access some WordPress function from my plugin
- WP 3-way voting system: On to something! Please help!
- Custom Settings Plugin Save foreach checkboxes
- Customise Grouped Product display in Woocommerce with custom column
- Change the behaviour of a button
- How to do admin ajax request in a plugin for rest api
- Action / Hook when a new plugin is added
- apply_filters() and call_user_func() to define and call a function outside a class
- Can someone explain what’s the use of parse request function in WordPress?
- Add default value from selection
- function add custom fields to media gallery
- Override category archive page title (not the head title)
- Where do I hook to have the server do something in PHP on block attribute change?
- The function called on the wp head hook becomes null
- Make visible page only in the trash
- Redirection from a specific page for users logged in but not with membership
- WordPress: I wanted to use Add rewrite rule multiple times for multiple CPT in my plugin
- Why would one specify multiple arguments when using get_previous_posts_link() which takes only one parameter?
- I cant add is_admin control to plugin
- WordPress Ajax not returning Response
- ajax-action.php can’t find added action
- Post is uncatagorized in publish_post action
- How to show only specific category post by user role without plugin and restrict all other cats
- Does hooking into a plugin action / filter override the plugin’s function for that hook?
- WordPress Plugin Boilerplate – add actions and/or filters based on user’s role
- do_action from within a class does not seem to work
- Remove tag from all posts when publishing new post
- WordPress plugin how to run function when button is clicked
- remove different admin menu for specific users
- WordPress Reset password Strength set to medium
- Add function to Dokan ajax class
- foreach argument to get specific file types getting too many returns
- add_option_{$option} action hook not being called
- Remove from a div by class name from post page if post author role is not administrator
- Function not working on any file other than the main plugin file
- Building WordPress Themes With Bootstrap with Adi Purdila → TutsPlus
- Does WordPress have something like timer hook?
- Ajax not working to insert, query and result data
- Associating special meaning with user id 0
- action callback, for action dispatched as reported by hook sniffer, not called
- Template file structure , wordpress hook for altering the template
- WordPress permalink setting
- How can I see a varibles value when my plugin runs?
- How can I set a dynamic value for post_updated_messages based on return value of post_updated?
- How can I add recent posts to menu like mashable
- How to use get_pages( ) correctly with ‘child_of’ to replace page with child page