Get post-meta value of all custom-posts – lowest to highest year-count?

something like this should do the job: global $post; $years = array(); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); $this_year = get_post_meta( $post->ID, ‘event_date’, true ); if ( $this_year = date( ‘Y’, $this_year ) ) { if ( ! in_array( $this_year, $years ) ) { $years[] = $this_year; } } … Read more

How can I access a post’s feature image outside the loop?

On a single post page the $post variable should work for you. It is set well before the page header prints. You will need get_post_thumbnail_id and wp_get_attachment_image_src if (is_single()) { $thumbid = get_post_thumbnail_id($post->ID); $imgsrc = wp_get_attachment_image_src($thumbid); $src = $imgsrc[0]; // wp_die(var_dump($src)); // debugging/confirmation } I don’t know how your theme is written or how that … Read more

Loop and add Specific Categories and Products Images

In your functions.php function show_all_thumbs() { global $post; $post = get_post($post); $images =& get_children( ‘post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent=”.$post->post_parent); if($images) { foreach( $images as $imageID => $imagePost ){ unset($the_b_img); $the_b_img = wp_get_attachment_image($imageID, “thumbnail’, false); $thumblist .= ‘<a href=”‘.get_attachment_link($imageID).'”>’.$the_b_img.'</a>’; } } return $thumblist; } In your page template file: $loop = new WP_Query( array( ‘post_type’ => ‘demo’, // or whatever … Read more

Only display latest custom taxonomy post

You should save the ID of the first post in a variable (e.g $splash_post_id) and in the next loop, use “post__not_in” => $splash_post_id , in the $args array. $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => ‘1’, ‘order_by’ => ‘date’, ‘order’ => ‘DESC’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘theme’, ‘field’ => ‘slug’, ‘terms’ => … Read more

Plugin is creating posts twice

The code does not adds posts twice – checked in my local installation. You have got errors in it: $my_post = array( ‘post_title’ => $title, ‘post_date’ => $insDate, ‘post_content’ => ‘$url’, ‘post_status’ => ‘public’, ‘post_type’ => ‘post’, ); Should be $my_post = array( ‘post_title’ => $title, ‘post_date’ => $insDate, ‘post_content’ => $url, ‘post_status’ => ‘publish’, … Read more

Limiting the amount of posts retrieved by the loop

The code you posted does not query for any content at all. To do that, use the WP_Query object. Please do not use query_posts, especially for secondary Loops. From the Codex: // The Query $the_query = new WP_Query( $args ); // The Loop while ( $the_query->have_posts() ) : $the_query->the_post(); echo ‘<li>’ . get_the_title() . ‘</li>’; … Read more

how to run loop in function.php that sends email based on specific conditions?

The post’s data is passed as an argument to the function hooked to transition_post_status, so you don’t need to query for anything (also, your query is a bit strange, using both WP_Query and query_posts, but that’s a separate matter). Here’s a trimmed version of your function showing the important changes: function a_new_post( $new_status, $old_status, $post … Read more