it looks like the problem is caused by the “Post Types Order” plugin I
have installed
Yes, I believe so because your code actually worked for me, but after I installed and activated the plugin, your code no longer worked as expected.
I have it set to not order
newspost types, but for some reason it’s
still adding its sorting to the main query.
I don’t know how you set it, but try one of these:
-
Set
ignore_custom_sort(it’s a customWP_Queryparameter) totruelike so:switch ( $order_by ) { case 'news-date': $query->set( 'meta_key', 'date' ); $query->set( 'orderby', 'meta_value_num' ); $query->set( 'ignore_custom_sort', true ); break; } -
Or you can also use the
pto/posts_orderby/ignorehook to disable the plugin’s sorting:add_filter( 'pto/posts_orderby/ignore', function( $ignore, $order_by, $query ){ if ( 'lesson' === $query->get( 'post_type' ) ) { $ignore = true; } return $ignore; }, 10, 3 );
Related Posts:
- Filter next_post_link() and previous_post_link() by meta_key?
- how to get posts by custom post type then display Custom fields?
- Automatically fill custom field value on post publish/update
- Make permalinks based on an ACF-field
- How to sort a table of custom posts by column containing custom field
- Insert slider (Custom Post Type) into pages
- get terms that have post with custom post type between 2 values
- Archive filter disappears on no results?
- Linking three taxonomies with ACF
- WordPress custom post type archive with description
- How to replace custom post type slug with an ACF value?
- Link users to a custom post type
- How to display Custom Post Type Post based on Tag with Shortcode Parameter?
- Validate custom fields before save using WordPress Rest API
- get_posts of Custom Post Type AND Custom Taxonomy
- How can I dynamically add a post to a custom post type which uses a custom field?
- the_content() not outputting anything (Advanced Custom Fields)
- Custom Taxonomy terms aren’t getting referenced or saved in Quick Edit or Bulk Edit, only on Single product page?
- custom post type WYSIWG removes paragraphs when displayed
- ACF From & To Date Validations
- Exclude objects from WordPress API based from ACF field using rest_prepare_{$post_type}
- Rewrite Rule for showing Parent/Child Relationship between Two Hierarchical Custom Post Types
- Order Custom Post Type by Custom Field Value
- Retrieve custom field from Contact Form 7 [closed]
- Lists custom taxonomy terms that has specific custom field value assigned to the term (not post)
- How to update post meta on uploaded image from a custom form?
- Multiple Frontend Filters Using Advanced Custom Fields
- WebP Fallback for Inline Background Image in Style Attribute
- Adavnced custom fields relationship query plus query inside
- Query based on custom fields start and end date
- Why is my WP Query not returning first result’s post meta?
- Recoverable Fatal Error – Object of class WP_Post could not be converted to string
- How to get a custom type post data when it has a connection with another custom type post?
- Custom post type showing same Post on all Pages
- How can I add a shortcode to query Custom Post Type with ACF in WordPress?
- ACF for custom post type archive pages: which hook to use?
- Distribute Custom Post in different pages
- How do I replace the post title with a custom field?
- Advanced custom fields Post Object image field not displaying in custom post type single.php
- Sum and count of custom field values
- How do I show a link or ‘Read More’ button on a custom field excerpt when it is less than the word limit
- meta query not retrieving posts
- Custom Post Type with Configurable Sidebar via ACF
- Get A Custom Field From A Custom Taxonomy Of A Custom Post Type [closed]
- Custom Sidebar in Editor (not Widget) for Custom Post Type in Genesis
- SQL query – get ids – Advanced Custom Fields / WPeC
- How to set a ‘page’ as parent of a custom post type?
- Custom front-end form for adding post – Category problem
- Using ACF values in nested WP queries for CPT with date values in the past
- Create/populate Custom Posts ACF fields from external JSON file
- WordPress URL rewrites using Advanced Custom Field
- Custom Post Type and Structure Question
- Query posts by current ACF meta key value on single page as related posts
- Show custom post type event if current day using ACF
- Display Custom Field or Custom Taxonomy in front page /post/product
- Why do my custom post types stop displaying over time?
- How to access repeater field of a custom field?
- Filter posts by their related field’s custom field
- If ACF Post Object post has custom taxonomy term…
- ACF Pro Accessing fields on a Custom Post Type
- Modify Publish Metabox location on CPT
- Some posts not displaying by taxonomy term
- Save_post acf data not updating category of post type
- Permalink URL connection between two custom types
- Display Specific Posts at Start of Loop
- How to display custom post type pagination buttons when processing AJAX request
- Adding specific custom fields (images) to post excerpt
- filter using custom fields
- Show specific posts with WP_Query using ACF Post object
- Display custom tax in “while” loop
- Autofill advanced custom field with user data
- Advanced search form with multiple custom fields
- Custom post type option page template
- CPT: execute code after load if parameter is set
- How to get a custom post type archive paged when using a custom field for post sorting?
- ACF Post Content Not Being Searched
- Fixed custom fields depending on posttype/category
- Group/list/sort custom post type posts by date in tabs from acf datepicker field
- Grouping and paging CPT events by month with custom field date
- Can’t pick up a field created with Advanced Custom Fields
- Custom post tag images not displaying with ACF
- using ACF datepicker to filter posts on a page
- Get post id of permalink for a specific custom post type?
- If you’re calling a dynamic css inline style does that div have to be in the loop?
- How to query the content of a specific custom post type?
- If i have custom post type with 5 custom fields do i have to create a new loop to reference each one?
- Copying custom field value in to title
- How to show animal lineage/pedigree in WordPress?
- Custom Post Type Loop breaking php
- Styling first post using Advanced Custom Fields
- ACF – Query relationship without ID
- ACF Relationship: Group posts by parent category term, then child [closed]
- ACF Field to set Publish Date – Post Duplication upon Update
- Getting ACF relationship field information
- How to I add count of custom posts listed in a post as a prefix to its title
- Is it possible to specify a time interval (from, to) in ACF with date picker, or other custom field?
- Why custom search engine only searches in post titles of custom posts?
- Display ACF object field data using Elementor Custom Query
- ACF Pro simple Business Directory – Requesting assistance with created Templates and associated Functions.php Coding
- Advanced Custom Fields Custom Post Types Heirarchy