Problems with database query after upgrading
-
I have created a site, where the editor has a posibility to add related posts to a post.
Now, when a page is shown, all related posts are presented below the content. A related post is presented by a title, a thumbnail and some text. The text comes from a custom field (_custom_introduce_text) that I pick up using this:
$manchet = $wpdb->get_results("SELECT meta_value FROM wp_FreshFarm_postmeta WHERE post_id=".$key->ID." and meta_key='_custom_introduce_text'", 'OBJECT');
I will start by saying that this actually worked before upgrading to 3.5.1, so I’m at a loss why it’s not working anymore.
If I “hard code” the query to e.g.
$manchet = $wpdb->get_results("SELECT meta_value FROM wp_FreshFarm_postmeta WHERE post_id=476 and meta_key='_custom_introduce_text'", 'OBJECT');
then a result is returned.If I write $key to the screen this is not empty.
But whenever $key is part of the query, nothing is returned from the database.
This is the “full” code that I’m processing:
<?php $related_posts = MRP_get_related_posts( $post->ID ); if( $related_posts ) {?><h2>Relaterede artikler</h2> <ul class="opsamlingPost"> <?php foreach( $related_posts as $key=>$value ) { ?> <li> <a href="<?php echo get_permalink($key); ?>"> <?php echo get_the_post_thumbnail($key, array(220,220)); ?> <h2><?php echo get_the_title($key); ?></h2> <?php $manchet = $wpdb->get_results("SELECT meta_value FROM wp_FreshFarm_postmeta WHERE post_id=".$key->ID." and meta_key='_custom_introduce_text'", 'OBJECT'); if( $manchet ) foreach( $manchet as $my_manchet) { ?> <p><?php echo $my_manchet->meta_value; ?></p> <?php } ?> </a> </li> <?php } ?> </ul>
Any help is much appreciated ??
- The topic ‘Problems with database query after upgrading’ is closed to new replies.