Hello,
I am trying to add a custom field to the postslider.php file but its not working.
i have tried
$stock_availability = get_post_meta( get_the_ID(), ‘stock_availability’, true);
if ( ! empty ( $stock_availability ) ) {
echo $stock_availability; // also tried return instead of echo
$meta_out .= $stock_availability;
$output .= $stock_availability;
};
Hey S-edwards,
Thank you for the inquiry.
Where did you add the code in the postslider.php file? You may need to replace the get_the_ID() function with the $the_id variable as shown below.
$stock_availability = get_post_meta( $the_id , ‘stock_availability’, true);
Best regards,
Ismael
Hi Ismael,
I added it just after the post meta is added. I have pasted the code below for your reference and changed it to get_the_ID but still no luck. I didn’t add the whole file, there is too much code.
The bit im talking about is right at the end
Hi,
Thank you for the info.
Try to look for this code in the postslider.php file around line 924.
if( ( $show_meta && ! empty( $excerpt ) ) || in_array( $show_meta_data, array( 'always', 'on_empty_content' ) ) )
Above that line, add this code.
$stock_availability = get_post_meta($the_id , 'stock_availability', true);
if ( ! empty ( $stock_availability ) ) {
$output .= "<div class='slide-meta-availability'>Availability: ". $stock_availability ."</div>";
}
Please check the private field for the screenshot.
Best regards,
Ismael
Thats perfect thanks Ismael, All i need to do now is a little CSS which i can handle.
thanks for the help, good as always..
Hi,
Great, I’m glad that Ismael could help you out. Please let us know if you should need any further help on the topic or if we can close it.
Best regards,
Rikard
hey you can close it thanks, sorry for the delay