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 can you check if you are in a particular page in the WP Admin section? For example how can I check if I am in the Users > Your Profile page?
- How to override existing plugin action with new action
- Which hook should be used to add an action containing a redirect?
- Why does WordPress add 0 (zero) to an Ajax response?
- WordPress Update Plugin Hook/Action? Since 3.9
- function deactivate_plugins does not exist
- Understanding WordPress functions’ naming conventions
- add_action with a class method is causing fatal errors
- Do I need to call do_action in my plugin?
- How Do I Load My Action Earlier Enough?
- Which to use to execute code during the saving of a plugin settings page?
- How do I Make a Theme “plugin-ready”?
- A Post is saved twice or more during add_action(save_post)
- How can i list current author’s categories?
- 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()?
- Change of query var in pre_get_posts not maintained
- When is it too late to call the action wp_enqueue_scripts?
- Dynamically Override Fancy Title
- Odd behaviour with submenu link creation
- Problems with removing admin bar
- Problem with `wp_mail()`
- Calling a function from functions.php in custom page/ blog post
- Call to undefined function get_blog_option()
- Plugin development: is adding empty index.php files necessary?
- Undefined function wp_set_password
- Create a plugin to change the action to which a function is hooked
- Plugin Uninstall and Deactivate via Options Menu
- admin_notices not displaying in plugin
- How can I add a CSS rule to edit.php?
- Widget update function not saving values
- Getting admin notices working for plugin errors
- Which are the hooks run before/after when a category’s deletion?
- add more custom post types and custom role to the code
- How to use WP_Term with (menu) argument in the wp_nav_menu?
- WordPress after content Hook & external template part
- override pluggable.php functions
- An echo line in a transition_post_status action leads to “cannot modify header information – headers already sent by”
- Namespaced action and filter tags
- creating custom function to log actions in plugin
- Adding Default Settings to Theme My Login plugin
- add_rewrite_rule works in themes function php but when moved into plugin it stops working
- Maximum lifetime for nonce
- Where can i find wordpress auto update code flows?
- Adding option to Gallery shortcode
- Plugin with action ‘save_post’ needs to press publish twice on order to publish
- Adding rewrite rule dynamically
- Remove unwanted elements for a wp_nav_menu
- wp_set_object_terms not updating database without a die()
- mysql_real_escape_string() vs. esc_sql() in WordPress
- Show error message after exception handled
- I have 2 plugins using the same wp_login action hook and one is not working
- Checking for existence of a page by title?
- 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 to modify files inside wp-includes directory in wordpress
- Fatal error: Call to a member function get_page_permastruct() on a non-object
- Function/Class to list categories with checkboxes
- Bug: Post needs to be updated twice when adding action for save_post hook
- Delete data from database using row action
- 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
- WordPress multisite,use same cookies across all website?
- unregister_setting() vs delete_option() for plugin update
- How to change WooCommerce loop product title HTML output in single product page and archive page
- wp_schedule_event is registered but function isn’t running
- 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()
- WP 3-way voting system: On to something! Please help!
- Custom Settings Plugin Save foreach checkboxes
- function add custom fields to media gallery
- Where do I hook to have the server do something in PHP on block attribute change?
- Make visible page only in the trash
- WordPress: I wanted to use Add rewrite rule multiple times for multiple CPT in my plugin
- WordPress Ajax not returning Response
- Post is uncatagorized in publish_post action
- Remove tag from all posts when publishing new post
- remove different admin menu for specific users
- WordPress Reset password Strength set to medium
- foreach argument to get specific file types getting too many returns
- Remove from a div by class name from post page if post author role is not administrator
- Ajax not working to insert, query and result data
- Associating special meaning with user id 0
- WordPress permalink setting
- How can I add recent posts to menu like mashable
- Why is ‘register_activation_hook’ undefined?
- Dynamic banner for use on external sites
- How can i call from custom fields to the category editor?
- Why does this fail: Disabling plugins enqueue_script() in functions.php
- Apply function on all action hooks?
- How to plugin function code move to theme function.php ? I’ve tried below code but not working [closed]
- WordPress simple ‘Hello World’ plugin – problems