I was trying to get results of a post meta relationship for a specific post id.
On a different language other than en_GB it seems to stop the function returning an array of results.
$meta_key = "your_key";
$meta_key = "your_post_id";
$sql = $wpdb->prepare(
"SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key = %s AND post_id = %s",
$meta_key,
$post_id
);
$related_ids = $wpdb->get_col($sql);
this strangely provides a different result than using get_post_meta.
I did not want to sync my custom fields as it creates a huge overhead.
I don’t know if this is a bug or by design.
]]>I use the following code to add the contents of some custom checkout fields to my invoices and packing slips:
function custom_order_info_fields( $fields, $order ) {
$custom_fields = array(
array(
'label' => 'Vergi Dairesi:',
'value' => get_post_meta( $order->get_id(), '_billing_vergidairesi', true ),
),
array(
'label' => 'T.C./Vergi No:',
'value' => get_post_meta( $order->get_id(), '_billing_tckimlik_vergino', true ),
),
);
$fields = array_merge( $fields, $custom_fields );
return $fields;
}
add_filter( 'wcdn_order_info_fields', 'custom_order_info_fields', 10, 2 );
The code works as intended except it gives empty values for the custom fields. There are no errors in debug logs, and when I dump some variables with:
var_dump(get_post_meta( $order->get_id(), '', false ));
I see the get_post_meta() returns data from my db table wp_postmeta instead of wp_wc_orders_meta where the custom fields are stored. wp_postmeta does have entries for every orderID that has a successful payment, because my payment gateway plugin stores them there, I’m not sure how or why.
Why does this happen and how do I make get_post_meta() return custom checkout fields?
Everything else seems to work fine. Below is my related config:
King Regards
SDC
]]><!-- Loop -->
<?php
$link = get_post_meta(get_the_ID(), 'link', TRUE);
if ( have_posts() ) {
while ( have_posts() ) : the_post(); ?>
<p><a href="<?php echo $link; ?>"><?php the_title(); ?></a></p>
<?php
get_template_part( 'parts/content', get_post_format() );
endwhile;
}
else { ?>
<div class="no-results"><p><?php _e('No posts found.', 'vega'); ?></p></div>
<?php } ?>
<!-- /Loop -->
Any assistance appreciated.
Thanks!
]]>I’m a newbie in wordpress, finding it difficult to retrieve author name from custom get post meta api
Below is snippet of my code
add_action( 'rest_api_init', 'my_register_template_hook' );
function my_register_template_hook() {
register_rest_field( 'post', // any post type registered with API
'appp',
array(
'get_callback' => 'my_get_hook_data',
'update_callback' => null,
'schema' => null,
)
);
}
function my_get_hook_data( $object, $field_name, $request ) {
$data['post_detail']['below_title'] = '<span class="schedule-time">' . get_post_meta( $object['id'], 'author', true) . '</span>';
$data['post_detail']['above_title'] = '<div class="post-featured-wrap">' . get_the_post_thumbnail( $object['id'], 'large', array( 'class' => 'post-featured' ) ) . '</div>';
return $data;
}
I could only retrieve featured image
]]><?php echo get_post_meta($post->ID, "_EventStartDate", true); ?>
This isn’t outputting anything?
]]>I have this line of code:
<?php echo ‘Course ID: ‘ . get_post_meta(17234, ‘_lesson_course’, true); ?>
I’ve stripped it out of a larger function, but I can’t even get this simple one to work. I’ve found the item in the database (screenshot: https://snag.gy/1IKwl4.jpg)
But it just returns back:
Course ID:
In other words, no value for the _lesson_course meta data.
I’ve double checked, there’s only one record, so it’s not an issue of pulling the wrong one. I’m stumped. Any ideas?
]]>I’m using Divi, and added the following code below the post content:
<?php if(get_post_meta($post->ID, 'store-url', true) !== '') { ?>
<div class="store"><a href="<?php echo get_post_meta($post->ID, 'store-url', true); ?>">Purchase a digital copy from $4 here. Up to 5184 x 3456 pixels in size</a>.</div>
<?php } ?>
I have a single custom field of name store-url
with a value of a URL.
When I view a single post, I receive a white screen of death.
Help appreciated.
Regards,
Steve
The if statement just checks if English or French is selected in qTranslate.
<?php while ( have_posts() ) : the_post(); ?>
<?php //This checks what language qTranslate has selected and returns the appropriate ShortDesc
if (ppqtrans_getLanguage() =="en") {
$key = "byline_en";
$description = get_post_meta($post->ID, $key, true);
}
if (ppqtrans_getLanguage() =="fr") {
$key = "byline_fr";
$description = get_post_meta($post->ID, $key, true);
}
?>
<div class="product_thumbnail">
<a href="<?php the_permalink() ?>">
<?php //the_post_thumbnail grabs the post's "featured image" this feature has added theme support in the child theme functions.php ?>
<?php the_post_thumbnail('thumbnail', array('class' => 'thumbnail')); ?>
</a>
<?php //This piece of code figures out the corrosponding post_title of the featured image ?>
<h1 class="post_caption"><?php the_title(); ?></h1>
<?php echo $description; ?>
</div> <!-- product_thumbnail -->
<?php endwhile; // end of the loop. ?>
]]>