Ordering posts by metadata
Try meta_value_num ‘meta_key’ => ‘metadata1’, ‘orderby’ => ‘meta_value_num’ Add these 2 parameters to $args. This does the sorting considering metadata1 as numeric
Try meta_value_num ‘meta_key’ => ‘metadata1’, ‘orderby’ => ‘meta_value_num’ Add these 2 parameters to $args. This does the sorting considering metadata1 as numeric
You can use get_the_author_meta function. You can learn more about it here: https://developer.wordpress.org/reference/functions/get_the_author_meta/ Usage in your case: <a href=”https://wordpress.stackexchange.com/questions/290522/mailto:<?php echo get_the_author_meta(“user_email’);?>?subject=<?php the_title(); ?>”>Apply</a>
A very basic solution would be to use the Transients API, an example… function setPostViews($postID) { $user_ip = $_SERVER[‘REMOTE_ADDR’]; //retrieve the current IP address of the visitor $key = $user_ip . ‘x’ . $postID; //combine post ID & IP to form unique key $value = array($user_ip, $postID); // store post ID & IP as separate … Read more
<?php // query posts $query_property = query_posts( array( ‘orderby’ => ‘date meta_value’ // orderby date AND meta value ) ); // First loop $query_feat = $query_string.’&meta_value=on&meta_key=property_featured’; // Offset for second loop $query_all = $query_string.’&offset=3&meta_key=property_featured’; // First loop if ( $query_feat->have_posts() : while ( $query_feat->have_posts() ) : # etc…. // do stuff endif; // Second loop … Read more
For mutually exclusive values use post meta. It is faster to read than assigned taxonomies too. It is possible to create your own interface: Set the parameter show_ui to false when you register the taxonomy. Register a meta box where you print out all existing taxons with radio boxes. Add a save action to assign … Read more
i ended up building a plugin that enforces radio buttons for any taxonomy. http://wordpress.org/extend/plugins/radio-buttons-for-taxonomies/ for the project in question i will probably also save the taxonomy as meta. sucks that i need/want half the ability of taxonomy (knowing other available terms, etc), but need the sorting by meta.
Querying posts with meta value that begins with a certain pattern
For anyone who may have a similar need, I solved this the following way (on authors.php): First I get the author ID: $author = get_user_by( ‘slug’, get_query_var( ‘author_name’ ) ); // ID is accessed this way: $author_id = $author->ID; I then created a custom query: $query = ” SELECT p.* FROM $wpdb->postmeta m JOIN $wpdb->posts … Read more
Looking at your code, it appears all meta keys are prefixed with _cmb_. Your start time key is text_datetime_timestamp, so combined with the prefix, you want to fetch: get_post_meta( get_the_ID(), ‘_cmb_text_datetime_timestamp’, true ); Note the third parameter, which will retrieve a single value if set to true, as it’s possible to save multiple values under … Read more
This snippet is good enough, use it with $wpdb. In this case I would use : <?php add_action( ‘before_delete_post’, ‘my_func’ ); function my_func( $postid ){ // We check if the global post type isn’t ours and just return global $post_type; if ( $post_type != ‘my_custom_post_type’ ) return; // My custom stuff for deleting my custom … Read more