In order to query products based on custom fields, from the plugin advanced custom fields, i have to use this wp query script, to query it correctly.
However, when i copied this script, changed the needed values, and inserted it into functions.php, it crashes the site.
I believe its a parse or syntax error because its using a lot of . I have tried removing some of them, still no results. When all the other scripts above it has been removed (irrelevant), then it looks like this:
<?php
<?php
add_action( 'wp_ajax_posts_by_brand_action', 'posts_by_brand_action_callback' );
function posts_by_brand_action_callback() {
global $wpdb; // this is how you get access to the database
$brand = $_POST['brand'];
echo $whatever;
// ----- START OF BRAND FILTER CODE
// args
$args = array(
//'numberposts' => -1,
//'post_type' => 'event',
'meta_key' => 'brand',
'meta_value' => $brand
);
// query
$the_query = new WP_Query( $args );
<?php if( $the_query->have_posts() ): ?>
<ul>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
// ------ END OF BRAND FILTER CODE
wp_die(); // this is required to terminate immediately and return a proper response
}
?>
How do i go a about this? Would it be correct to say, that shouldn't be used inside an ?
?>
in the line above// ------ END OF BRAND FILTER CODE