Can’t get meta values to save

Figured it out: There was a space in the field ID, and the $_POST key would collapse it. So the ID’s weren’t matching up in the foreach loop in my save function. I solved this with a sanitizing function on the IDs for my meta fields. I was further confused because my admin notices that …

Read more

Create Shortcode shows only posts with custom_field meta

You need your shortcode to accept attributes. A shortcode with attributes would look like: [publication year=”2017″] Then in your add_shortcode callback function you receive attributes in the first parameter of the function: function wpse_279094_publication_shortcode( $atts ) { echo $atts[‘year’]; } add_shortcode( ‘publication’, ‘wpse_279094_shortcode’ ); You want to be able to account for a user not …

Read more

Get the total Author Favorited posts

<?php $args22 = array( ‘post_type’ => array (‘menus’, ‘recipes’ ), ‘author’ => get_queried_object_id(), ‘meta_query’ => array( ‘meta_key’ => ‘simplefavorites_count’, ‘value’ => ‘0’, ‘compare’ => ‘>=’, ), ); $my_query = new WP_Query( $args22 ); echo ‘Found posts: ‘ . $my_query->found_posts . ‘<br />’; // declare variable and set total votes to 0 $total_fav_count = 0; if …

Read more

Using Orderby and meta_value to order natural/alphanumerical

The orderby argument is limited by what is possible in MySQL, and it’s not good at natural alphanumeric sorting like you describe. Possible options include: Rewriting the values with leading zeros, e.g. “CA05” Creating a separate “Sort Order” column that just stores an integer, and ordering by that. Separating the letters and numbers into two …

Read more