Access Serialized Post Meta Values
Access Serialized Post Meta Values
Access Serialized Post Meta Values
Looks like you have the image URL saved as a custom field and not the attachment id so first get the attachment id using the URL using Philips awesome function and then use wp_get_attachment_image_src() to get the attachment attributes : $attch_id = pn_get_attachment_id_from_url(get_post_meta($post->ID, ‘img1’, true)); $image_attributes = wp_get_attachment_image_src( $attch_id ); // returns an array //$image_attributes … Read more
The ID of the parent post is in $post->post_parent. When a post has no parent, that number is 0. So … if ( is_singular() ) { global $post; if ( 0 !== (int) $post->post_parent ) { $some_value = get_post_meta( $post->post_parent, ‘some_metabox_param’, true ); if ( ! empty ( $some_value ) ) echo $some_value; } }
WordPress join posts with meta values of array type
Using mysql queries to delete custom post types based on meta_value
This will work fine. global $wpdb; $querydetails = ” SELECT wposts.* FROM $wpdb->posts AS wposts INNER JOIN $wpdb->postmeta AS wpostmeta ON wposts.ID = wpostmeta.post_id WHERE wposts.post_status=”publish” AND wposts.post_type=”match_report” AND wpostmeta.meta_key = ‘report_home-select’ AND wpostmeta.meta_value=”198″ “; $teaminfo = $wpdb->get_results($querydetails, OBJECT); Try it.
<?php if(strlen(get_post_meta($post->ID, ‘recent_action’, true)) !== 0){ ?> <a class=”button” href=”https://wordpress.stackexchange.com/questions/107002/<?php echo get_post_meta($post->ID,”recent_action”, true); ?>”>Recent Action Link</a> <?php } elseif(strlen(get_post_meta($post->ID, ‘related_link’, true)) !== 0){ ?> <a class=”button” href=”https://wordpress.stackexchange.com/questions/107002/<?php echo get_post_meta($post->ID,”related_link”, true); ?>”>Related Link</a> <?php } elseif(strlen(get_post_meta($post->ID, ‘imp_docs_link’, true)) !== 0){ ?> <a class=”button” href=”https://wordpress.stackexchange.com/questions/107002/<?php echo get_post_meta($post->ID,”imp_docs_link”, true); ?>”>Important Documents Link</a> <?php } ?> or better yet … Read more
Get value from post meta array, and add it as a category
<?php $args = array(‘post_type’=>’products’,’posts_per_page’=>10,’number_posts’=>10); $products = get_posts($args); foreach($products as $product) { $productid = $product->ID; echo $producttitle = $product->post_title; echo $productdescription = $product->post_content; echo get_post_meta($productid ,’price’, TRUE); echo get_post_meta($productid ,’product_name’, TRUE); echo get_post_meta($productid ,’size’, TRUE); } ?> if the value is empty it shows null otherwise
Maybe it can be solved at run-time. wp_get_attachment_image says: Returns an HTML image element representing an attachment file, if there is any, otherwise an empty string. So, if the post meta is set, but an empty string is given, we should delete the post meta. $default=”<img src=”” . get_stylesheet_directory_uri() . ‘/img/team-logo.png” />’; if ( get_post_meta( … Read more