Setting post_id for single.php based on URL without a redirect

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 … Read more

How to apply pre_get_posts to a custom query?

For some use cases, couldn’t you use $query->get() to target specific custom queries? For example: say you’ve got a custom query for a slider post-type. Perhaps something like this? function wpse64950_filter_pre_get_posts( $query ) { if ( ! is_main_query() ) { if ( ‘slider’ == $query->get( ‘post-type’ ) ) { // This is a query of … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)