I am having an issue to display results from a search form in a page.
I have in my header.php a custom search form :
<form action="<?php echo site_url('/pagesearch/')?>" method="get" id="adminbarsearch">
<input type="search" id="place" name="mydata" />
<input type="submit" class="adminbar-button" value="Rechercher"/>*/?>
</form>
When a user submits the form, I retrieve the data and modify it, through this code in my functions.php :
if ((isset($_GET['mydata'])) && (!empty($_GET['mydata']))){
$q = sanitize_text_field($_GET['mydata']);
$search_posts_id = array();
$search_args = array(
's' => $q,
'fields' => array('ids', 'post_type'),
'post_type' => 'my_custom_posttype'
);
$search_query = new WP_Query($search_args);
if ( $search_query->have_posts() ) :
$search_posts_id = array_unique(wp_list_pluck( $search_query->posts, 'post_title', 'id' ));
$search_posts_id = implode( ',', $search_posts_id );
else :
$search_posts_id = implode( ',', $search_posts_id );
endif;
wp_reset_postdata();
echo $search_posts_id;
The problem is that I would like to display the result which is $search_posts_id
in the "pagesearch" page of my website.
When I use the code above, it displays in the page but before the header and everything, and not in the content, between the header and the footer.
I don't know how to put this data correctly in the content.
Thank you very much for your help !