Making WordPress.org


Ignore:
Timestamp:
08/02/2024 12:26:40 AM (2 years ago)
Author:
adamwood
Message:

Learn: Sync with git WordPress/learn@36bd656

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2024/inc/query.php

    r13943 r13944  
    88add_action( 'pre_get_posts', __NAMESPACE__ . '\add_language_to_archive_queries' );
    99add_action( 'pre_get_posts', __NAMESPACE__ . '\add_excluded_to_lesson_archive_query' );
     10add_action( 'pre_get_posts', __NAMESPACE__ . '\filter_search_queries_by_post_type' );
    1011add_filter( 'request', __NAMESPACE__ . '\handle_all_level_query' );
    1112
     
    8283
    8384/**
     85 * Filter search queries by post type.
     86 * Only include courses and lessons in search results unless post_type is set, eg. for an archive search.
     87 *
     88 * @param WP_Query $query The query object.
     89 * @return WP_Query The modified query object.
     90 */
     91function filter_search_queries_by_post_type( $query ) {
     92        if ( ! is_admin() && $query->is_search() && $query->is_main_query() ) {
     93                if ( ! $query->get( 'post_type' ) ) {
     94                        $query->set( 'post_type', array( 'course', 'lesson' ) );
     95                }
     96        }
     97
     98        return $query;
     99}
     100
     101/**
    84102 * Modify the request.
    85103 *
Note: See TracChangeset for help on using the changeset viewer.