There’s a problem with your get_page_by_title()
usage, since you assume it returns the page ID, but it returns an object/array or null
. You also have to tell it about your custom post type.
I also assume your products are stored as custom post type cars.
Please try the following with a given product title (untested):
// DEBUG: Let's first try out an existing product title:
$product_title="Some product title"; #<-- Adjust this to your needs!
// User input:
// $product_title = filter_input( INPUT_GET, 'product', FILTER_SANITIZE_STRING );
// Search for pages with the above product title:
$product = get_page_by_title( $product_title, $output = OBJECT, $cpt="cars" );
// Product exists:
if( $product ) {
$query = new WP_Query( array( 'p' => $product->ID ) );
if( $query->have_posts() ) {
while ($query->have_posts()) {
$query->the_post();
the_title();
the_content();
}
}
}
Hopefully this could be a starting point for some further debugging.