Order by custom date field

I found the following solution: SELECT wposts . * FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = ‘datum’ AND wposts.post_type=”optredens” AND wposts.post_status=”publish” ORDER BY wpostmeta.meta_value ASC As other query_posts() methods / alternatives did not work very well.

Add a field to just ONE page

Take a look at the Custom Field Template plugin. It supports adding specific custom fields based on various conditions, which range from broad to fine-grained. You can, for example, limit the display of a particular set of custom fields to a particular page id.

How to query posts by month based on date custom field?

It is not clear what you’re using as a comparison, but WP Query supports meta query comparisons and even has a DATE type. For example: $query = new WP_Query( array( ‘post_type’ => ‘attraction’, ‘meta_key’ => ‘attraction_date’, ‘meta_value’ => ’10’, ‘meta_compare’ => ‘LIKE’, ‘type’ => ‘DATE’ ) ); Using 10 is not going to get you … Read more

Replacing custom field with shortcode

A shortcode like this [thumbnail height=100 width=100]http://urltoimage.com/image.jpg[/thumbnail] Would need this type of setup function content_insert_thumbnail($atts, $content = null){ global $post; extract($atts); $thumbnail = get_the_post_thumbnail($post->ID, array($height, $width)); $content .= $thumbnail; //Places the thumbnail after the content return $content; //Never echo a value from a shortcode function. } add_shortcode(‘thumbnail’, ‘content_insert_thumbnail’); To call this in your theme to … Read more

Display custom field only if it has a value

<?php $metacatname = get_post_meta( $post->ID, ‘related blog articles’, true ); if(!(empty( $metacatname ))): $my_query = new WP_Query( array( ‘category_name’ => $meta_cat_name, ‘posts_per_page’ => 5, ) ); if ( $my_query->have_posts() ): while ( $my_query->have_posts() ) : $my_query->the_post(); ?> <a href=”https://wordpress.stackexchange.com/questions/29266/<?php the_permalink() ?>” rel=”bookmark” title=”<?php the_title(); ?>”><?php the_title(); ?></a> <?php endwhile; endif; endif; wp_reset_query(); ?>

Searching with Multiple (Parallel) Criteria on Custom Fields?

have a look at WP_Query(); and use meta_query / tax_query arguments $args = array( ‘post_type’ => ‘product’, ‘meta_query’ => array( array( ‘key’ => ‘color’, ‘value’ => ‘blue’, ‘compare’ => ‘NOT LIKE’ ), array( ‘key’ => ‘price’, ‘value’ => array( 20, 100 ), ‘type’ => ‘numeric’, ‘compare’ => ‘BETWEEN’ ) ) ); $query = new WP_Query( … Read more