As pointed out in this answer, using the request
filter means that some (if not all) of WordPress’s is_*
functions are unavailable. Use the corresponding member functions of your new WP_Query
instead, as they should be available.
function graphene_alter_the_query( $request ) {
$dummy_query = new WP_Query();
$dummy_query->parse_query( $request );
if ( ! $dummy_query->is_category( 25 )) {
$request['gdsr_sort'] = 'rating';
} else {
$request['gdsr_sort'] = 'comment_count';
}
return $request;
}
add_filter( 'request', 'graphene_alter_the_query' );
Related Posts:
- Issues with title-tag and document_title_parts
- Remove Actions/Filters added via Anonymous Functions
- Add class to menu items of one specific menu (nav_menu_css_class)
- How to influence the information displayed on widget inside wp-admin
- Filter the query ONLY for the search results page
- opening links in new tab using – add_filter( ‘the_content’, ‘make_clickable’);
- Using add_filter() in Widgets
- Customize WordPress Media Manager – Media Window
- How to reduce original image quality on upload?
- Is it possible to use a forgot password url filter?
- Add body class of category parent
- Convert hyphen to underscore in permalinks
- Remove Page Title from Static Frontpage
- Programmatically Add Font-Awesome Icons to Category Widget
- Remove bulk actions based on user role or capabilities
- Default or Preset Content for Custom Post Types
- Override a class function to include a custom template
- How to override filter in child theme?
- How to change a certain text or term of WordPress into a custom into the whole site?
- Adding body class when post contains a specific shortcode
- Manipulate Output of wp_list_something: select menu instead of li’s
- How to use IF Statement in WordPress?
- Gravity Forms field entries into wp_query loop [closed]
- Post Pagination Showing Same Posts Every Page
- Show excerpt for only first post in query
- modify a function filter
- How would go about if I just want a temporary function?
- Generating rel=prev and rel=next only on wordpress categories
- How to make applyFilters function return false via functions.php
- Get current page_id before loop, in functions.php
- Which action hook to use for function?
- str_replace function in theme
- Can’t check if a post has thumbnail adding filter to get_post_metadata()
- Modify a function without editing template
- How do I add Bootstrap and LESS to my migrated WordPress site?
- How to add nav menu items to a specific position within a menu
- Passing values from a widget to a function within a plugin
- Publish/Update post is changing image links from file url to post url
- Disable auto-resizing of uploaded images, but only for certain filename
- Filter out other users comments. Visualize only own comments and editor role users’ comments
- Add to cart php not working [closed]
- Is possible add icon in title posts only in specific tag?
- create filter in functions.php
- Adding an external HTML link to a post thumbnail
- Replace a menu with widget or a custom template file programmatically
- woocommerce change currency per category [closed]
- Run wp_kses_decode_entities on atom feed?
- Can’t filter wp_get_attachment_link
- Override the WordPress core function wp_referer_field
- Modify post filter to set custom number of posts per page and exclude child posts
- Make wp_link_pages() suitable for Twitter Bootstrap markup
- Setting a default text for excerpts of a particular category
- How to edit the Tags within the image file URLs?
- Can’t properly set the_title add_filter to show short_URL
- Add_filter when value is no variable?
- (Woocommerce) Order by price when entering specific category
- How to edit classes in body tag?
- Filter nav menu items HTML tags and wrap inner text with span
- Possible to hook into Media Library preview File column and use a custom image?
- How to display the_archive_title() and the_archive_description() – “weird” interaction
- How to add custom li item to wordpress menu
- Native gallery custom html output
- The_content and Preg_replace in loaded Iframe [closed]
- How to edit/replace Parent functions.php function in Child Theme to add “Walker” class
- Functions Filter Question [closed]
- Is it possible to use add_filter in an included file in the child theme’s functions.php?
- Insert Content Before div#main from the functions.php File
- Changing the text of Upload/Insert on Posts and Pages Screen
- Any adverse effects of adding apply_filters to a function?
- Conditional custom menu?
- Get URLs for AJAX Filter Checkboxes WordPress
- How to display an image before title text in menu items
- Adding custom social icons to the social media icon block in the Gutenberg editor?
- Filter works on last selection but no others
- post value to function with Ajax and jQuery
- How Do I Unhook This Parent Theme Function?
- Allow user only create specific tags
- Child theme remove parent filter in functions
- Prevent function from triggering on current page
- Assign IDs to headings in ACF using functions.php
- Redirect specific author posts to another url
- Remove External Links from WordPress posts Using add_filter() in Theme functions.php
- $content is empty while using DOMDocument
- Hide disclaimer from summary excerpts
- Only seems to be displaying one child when there are supposed to be multiple
- Best way to add image to recent posts widget?
- Shortcode to eliminate and replace with
- previous_post_link inside of a function?
- Search and Replace Script Loader in Head Only Works in Footer
- Problem in outputting shortcode
- How to Add A Rel Filter to All Links?
- Print all inline styles to head
- Allow tags and attributes in post and pages content
- Override parent theme function that is not hooked or in the functions.php file
- child_of not working while searching
- Function Reference for custom link in Admin Menu Management Page
- How to Insert A List of Posts in A Category Written by the Author into the Author Archive
- Filter to strip unnecessary attributes
- function to show youtube videos within excerpt – if condition and apply_filters
- How can I modify or filter this variable in an existing class? (Mai Theme)