Reply To: Include Atributes in search

#13408

fespigado
Participant

Sorry Ernest,
but still looking for products in stock 0 searches.

I´ve add added 1 more condition but it does not work.

**********************************************************

add_filter( 'asp_results', 'asp_stock_to_content', 1, 1 );

function asp_stock_to_content( $results ) {
$custom_field = “_stock”;

foreach ($results as $k=>$v) {
if ($v->content_type != “pagepost” || $v->post_type != “product”)
continue;
if ( function_exists('get_field') )
$meta_value = get_field( $v->id, $custom_field, true ); // ACF support
else
$meta_value = get_post_meta( $v->id, $custom_field, true );
// Modify the post title to add the meta value
if ( !empty($meta_value) || $meta_value <=0)
$results[$k]->content .= '<br>Stock: ' . intval($meta_value) . '';
}

return $results;
}

Attachments:
You must be logged in to view attached files.