Here is the Code
function university_adjust_queries( $query ) {
if ( ! is_admin() && is_post_type_archive( 'program' ) && $query->is_main_query() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
$query->set( 'posts_per_page', -1 );
}
if ( ! is_admin() && is_post_type_archive( 'event' ) && $query->is_main_query() ) {
$today = date( 'Ymd' );
$query->set( 'meta_key', 'event_date' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'ASC' );
$query->set( 'meta_query', array(
array(
'key' => 'event_date',
'compare' => '>=',
'value' => $today,
'type' => 'numeric',
)
) );
}
}
add_action( 'pre_get_posts', 'university_adjust_queries' );
Related Posts:
- WP_Query – Order results by meta value
- Custom query with orderby meta_value of custom field
- How to enable revisions for post meta data?
- Any way to add custom options to Gallery Settings?
- Including custom fields in search?
- How to display all custom fields associated with a post?
- Sort posts by custom field numeric value using dropdown
- How to position a custom field before the editor
- passing argument to get_template_part() or a better way to code
- ACF – get_field() using ‘option’ as post_id not working
- Display thumbnail from custom field
- Bulk move (or copy) from a custom field to the post content?
- Populating meta box with select-list of existing posts, and assigning it to custom post types
- Getting Custom Field data from a page hierarchy
- limit amount of photos uploaded per cpt post
- Problem with adding exta field in metabox in custom post type
- Move value of one custom field to another
- Deleting a custom field field
- custom field to always to .get_the_title()?
- Displaying posts with only upcoming dates according their custom field date value
- How do I add custom_meta_box_id’s value?
- Get a post_id where meta_value equals something in a serialized meta_value field
- little help with a mySQL query to wp database
- Add WYSIWYG to Image Description field
- How do I query for a post by custom field?
- Including Database Generated Pages in Site Search [closed]
- Calling custom profile fields?
- How to save media files under custom folder without changing wp-config.php or changing media settings
- How can I sort homepage by a meta value?
- Performance of storing multiple meta fields vs one JSON encoded field [duplicate]
- get_posts that match a user-specified value on a page
- WP_User_Query pulling ACF to loop
- how to put a custom field value in variable
- Custom Metabox Not Saving
- How to add image attachment to post from a single meta key (Woocommerce)
- Custom Fields – Taller editing area
- How to add Advenced Custom Fields In Single Post
- How can I output a list of values for a custom field, and posts with those values?
- Manipulate javascript code from custom made admin page menu
- Add additional ‘description’ field for defined roles / role metadata?
- Change the main loop WordPress impact on the server?
- How to get categories with posts by custom field value?
- Meta Query returns wrong number of posts
- How to hide a custom field if there is not a value
- custom-meta-box checkboxes from loop won’t save
- Custom dropdown field added to media gallery; how to get it to save properly?
- Display Custom Field for a Specific Role, but not for Admin
- Correct syntax for retrieving custom field in CPT
- $TBA Getting Translated to $0 (Custom Fields)
- Walker class for sub-menu with ACF fields
- Hide text if one custom field out of two is empty [closed]
- Add custom fields to existing posts (admin pages)
- Multiple instances of TinyMCE are removing tag
- Echo the custom field value from the latest post from the ‘video’ post format?
- How do i get the attached images with custom value checked?
- How to disable Edit Post and Allow only Custom Field?
- Convert attachment ID into url?
- How to query an out put value?
- What’s the best way to implement custom widgets on a per post basis?
- Displaying Meta-Box Data Properly
- Retrive Image URL of Custom Fields in Theme
- Custom Fields Question
- do_shortcode close
- Search Results Page – Displaying Custom Meta Fields
- How do I convert all custom_field php timestamps in the database to js timestamps?
- Interrogate a page within a loop to check template type or custom meta data (Pages vs Posts)
- using advanced custom field to control css hover color
- Custom Field data only shows after manual post update
- Custom field Search with Relavanssi
- wordpress get_post_meta / the_meta to output custom field value
- How to show content of custom fields in search results?
- simple fields plugin custom query
- Set class if a meta value is set within post archive
- Allow HTML in Custom Metabox area
- Custom field metabox not showing in back-end
- checking liked user in wordpress rest api
- Custom Fields Permalink Plugin not observing hyphens
- will wp_insert_post write a new custom field to the database?
- Contact Form 7 List Building
- Link fields in User Admin list
- How to repeate custom field group with bulk image field
- ACF – Compare user and post data
- Advanced Custom Fields deleting some code and adding code for a slider
- How to format the various types of custom fields?
- Get file size from ACF repeater field
- Extra text’n’image field in a page
- Get first URL from custom field, download and set as featured image on post publish
- Query postmeta values, and return multiple post_titles for common meta value
- Set Value To Custom Field While Submit
- How to add an option to admin to add image that could be used as header?
- Custom Field: Display only if a specific key is selected outside the loop
- Show or hide lang=”ur” in main element
- How to query posts that have certain post meta keys, and sort by meta key and/or value
- sort a custom field base on the date or anything
- How to get the value of particular get $meta value in wordpress
- Add image custom attribute [closed]
- Retrieving custom field as shortcode
- Hiding custom fields when content is empty [closed]
- Foreach giving one too many list items, how can I remove the last empty line?
- I used a custom field for header image and can’t get it to show up on posts