How to Implement Search Functionality?

div class=col-lg-8
                div class=row
                    ?php
                    $search_term = get_search_query();
                    $term = get_term_by('slug', $search_term, 'blog_taxonomy');
                    $term_name = $term-name;
                    $args = array(
                        'post_type' = 'blog',
                        // 'title' = $search_term,
                        'tax_query' = array(
                            array(
                                'taxonomy' = 'blog_taxonomy',
                                'field'    = 'slug',
                                'terms'    = $search_term,
                                'orderby'   = array(
                                    'date' = 'DESC',
                                ),
                            ),
                        ),
                    );
                    $loop = new WP_Query($args);

                    if ($loop-have_posts()) {
                        while ($loop-have_posts()) {
                            $loop-the_post();
                    ?
                            div class=col-lg-6 col-md-6
                                div class=blog-content radius30 cB-shadow cBorder mw-100
                                    div class=blog-img text-center position-relative
                                        div class=date-time position-absolute
                                            div class=date
                                                h6?php the_time('j') ?/h6
                                            /div
                                            div class=month
                                                p?php the_time('M') ?/p
                                            /div
                                        /div
                                        ?php if (has_post_thumbnail($post-ID)) : ?
                                            ?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post-ID), 'single-post-thumbnail'); ?
                                            img src=?= $image[0] ? alt=
                                        ?php endif; ?
                                        img src=?php echo get_template_directory_uri(); ?/assets/images/blog/blog-logo.svg class=blog-logo alt=
                                    /div
                                    div class=blog-text
                                        h5?php the_title(); ?/h5
                                        h5?= $term_name ?/h5
                                        p class=p-gray
                                            ?php $content = get_the_excerpt();
                                            $trimmed_content = wp_trim_words($content, 25); ?
                                            ?php echo $trimmed_content; ?
                                        /p
                                        div class=py-3
                                            a href=?= the_permalink(); ? class=cmn-btnExplore more/a
                                        /div
                                    /div
                                /div
                            /div
                    ?php wp_reset_postdata();
                        }
                    }
                    ?
                /div
            /div 

Above is the code for my search Functionality, where I am using custom post type blog and custom taxonomy that is blog_taxonomy. I am able to get results only from tax_query or title.

I want them both searchable, as user either enters taxonomy name or post title in search bar. How to implement both ? tax_queries as well as commented 'title'.

Topic custom-taxonomy custom-post-types Wordpress search

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.