Display Post Meta in Header
Use get_the_ID(), the post object is not set up completely on wp_head(): if ( is_singular() ) $post = get_post( get_the_ID() );
Use get_the_ID(), the post object is not set up completely on wp_head(): if ( is_singular() ) $post = get_post( get_the_ID() );
First of all get_users_of_blog has been deprecated, so you should use get_users instead, or run a WP_User_Query. After that, the_author_meta echo the meta value, not return anything. To return the meta you should use get_the_author_meta() $blogusers = get_users( $args ); // for args see codex if ($blogusers) { foreach ( $blogusers as $bloguser ) { … Read more
This is because there is no relationship between the item id and the price when you are collecting the posted data. Do the changes as below. Change the sale_price to below to include the item id <input name=”sale_price[<?php echo get_the_id(); ?>]” type=”text” value=”<?php echo get_post_meta(get_the_id(), “_sale_price”, true); ?>” /> Then change the loop for collecting … Read more
Unless you are building a heavy web application, with billions of rows ( and maybe even then ), the number of rows for MySQL is not an issue. Saving your data in an array will make calling the data simpler (just one call), and keep the database smaller, but it will make parsing and searching … Read more
Use it like this <?php if ( in_category( ‘951’ )) { echo ‘Online. Todas las provincias’; } else { global $wp_query; $postid = $wp_query->post->ID; $meta = get_post_meta($postid, ‘provinciadestacada’, true); echo $meta; } ?> To do it in reverse as you want: global $wp_query; $postid = $wp_query->post->ID; $meta = get_post_meta($postid, ‘provinciadestacada’, true); if(!empty($meta)) { echo $meta; … Read more
get_post_meta() should only return false under a couple of circumstances: 269 function get_metadata($meta_type, $object_id, $meta_key = ”, $single = false) { 270 if ( !$meta_type ) 271 return false; 272 273 if ( !$object_id = absint($object_id) ) 274 return false; https://core.trac.wordpress.org/browser/tags/3.8.1/src/wp-includes/meta.php#L269 I don’t see how $meta_type could be wrong since it is hard-coded into get_post_meta(): … Read more
If you look at the 50+ similar questions on Stack Overflow you’ll see that you can only do so with considerable difficulty, and you won’t have a very efficient query once you get it working. MySQL just isn’t built to sort that way, and honestly the sort pattern you want is really very peculiar anyway. … Read more
Looking over it again, it seems as though you’re inserting the post twice. wp_insert_post returns the following (from the codex): The ID of the post if the post is successfully added to the database. On failure, it returns 0 if $wp_error is set to false, or a WP_Error object if $wp_error is set to true. … Read more
You can add this to form action: wp_set_post_tags( $post_ID, $tags, $append ) Function reference: wp_set_post_tags
I got your “broken” code in your answer to work and will explain why. First, here’s the edited code that wasn’t working for you: <?php //Get your post ID with a variable $this_post_id = get_the_ID(); //Removed get function from get_post_meta to make functionality clearer //I tend to avoid nesting functions that are grabbing post information … Read more