I am trying to query some custom posts so that I can iterate through them, extract the title of ecah and add the titles into an array. The reason I am doing this is so that I can then create a select field in woocommerce using the array contents to generate the options (haven’t done this bit yet)
Can anyone see where I’m going wrong with this snippet or provide any advice, I can’t get it to work. The site goes down and I get nothing in a var_dump
add_action('woocommerce_after_order_notes', 'custom_checkout_field');
function custom_checkout_field($checkout)
{
$args = array(
'post_type' => 'pickup-point',
'posts_per_page' => -1,
'post_status' => 'publish'
);
// Custom query to pull in the pickup points.
$query = new WP_Query( $args );
// Check that we have query results.
if ( $query->have_posts() ) {
$available_locations = [];
while ( $query->have_posts() ) {
$query->the_post();
array_push($available_locations, the_title());
}
}
var_dump ($available_locations);
}
// Restore original post data.
wp_reset_postdata();