ElasticPress – post content not displayed after custom search

Question

I have issue with ElasticPress.

After successful installation and connection of WordPress and ElasticPress and indexing few hundred posts for testing, i found everything in order until I tried to create custom WP_Query. The result page had only title lines but the post content was not displayed. In the search.php I wrote this

$wp_query = new WP_Query( array(
                    'ep_integrate'   => true,
                    'post_type'      => 'post',
                    'posts_per_page' => 20,
                    'tax_query' => array(
                        array(
                            'taxonomy' => 'category',
                            'terms'    => array( get_query_var('cat') ),
                            'field'    => 'term_id',
                        ),
                    ),
                ) );


                if ( $wp_query->have_posts() ) {

                    // Start the loop.
                    while ( $wp_query->have_posts() ) : $wp_query->the_post();

                        /**
                         * Run the loop for the search to output the results.
                         * If you want to overload this in a child theme then include a file
                         * called content-search.php and that will be used instead.
                         */
                        get_template_part('template-parts/content', 'search');

                        // End the loop.
                    endwhile;

                    // Previous/next page navigation.
                    the_posts_pagination(array(
                        'prev_text' => __('Previous page', 'twentysixteen'),
                        'next_text' => __('Next page', 'twentysixteen'),
                        'before_page_number' => '<span class="meta-nav screen-reader-text">' . __('Page', 'twentysixteen') . ' </span>',
                    ));

                    wp_reset_postdata();

                    // If no content, include the "No posts found" template.
                } else {

                    get_template_part('template-parts/content', 'none');
                }

Unfortunately I didn’t find anything about how to correctly use ElasticPress when building custom queries. All tutorials are simple, shows how to write new WP_Query and the results are built without any other programming.

The global post var is not empty, still the post content missing on page. WordPress is 4.6.1, ElasticPress is 2.1.2.

Can someone direct me to the correct way of creating custom queries and display the results. I know ES but I’m almost beginner in WP.

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/elasticpress-post-content-not-displayed-after-custom-search/">

ElasticPress - post content not displayed after custom search</a>
0
, fly 3 years 0 Answers 42 views 0

Leave an answer