-
AuthorPosts
-
December 6, 2021 at 8:16 am #1331670
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;
};December 6, 2021 at 2:07 pm #1331710Hey 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,
IsmaelDecember 7, 2021 at 1:04 am #1331772Hi 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
December 7, 2021 at 7:04 am #1331803Hi,
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,
IsmaelDecember 8, 2021 at 11:35 pm #1332038Thats perfect thanks Ismael, All i need to do now is a little CSS which i can handle.
thanks for the help, good as always..
December 9, 2021 at 6:51 am #1332068Hi,
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,
RikardDecember 14, 2021 at 6:52 am #1332714hey you can close it thanks, sorry for the delay
December 15, 2021 at 7:49 am #1332879 -
AuthorPosts
- The topic ‘add custom field to postslider.php’ is closed to new replies.
