Two near-identical custom field types – one works, the other doesn’t . What can cause this?

I found an older post showing what I was missing from my code, so it seems like I didn’t do a good enough search to begin with. For anyone wondering I was missing ‘compare’ => ‘LIKE’ from the query, so the code would look like this: $args_post = array(‘post_type’ => ‘release’, ‘orderby’ => ‘_custom’, ‘order’ … Read more

Woocommerce – How to populate custom select field with stored values on checkout page?

I just had a similar problem and solved it with a combination of PHP and jQuery. If $stored_value is what you have pulled from the DB and #billing_postcode is the id of the select-tag: <?php if ( !empty( $stored_value ) ) { ?> <script type=”text/javascript”> jQuery(document).ready(function($) { $(“select#billing_postcode”).val( “<?php echo $stored_value; ?>” ); }); </script> … Read more

get_posts that match a user-specified value on a page

Using a variable will make your code a little less repetitive: $case_history_code = get_field( ‘case-history-code’ ); if ( $case_history_code ) { // make the code lowercase $case_history_code_lower = strtolower( $case_history_code ); // use the lowercase inside of `get_posts` $myposts = get_posts( ‘numberposts=3&offset=0&category_name=” . $case_history_code_lower ); foreach ($myposts as $post) : setup_postdata($post); ?> <a href=”https://wordpress.stackexchange.com/questions/220489/<?php the_permalink(); … Read more

Advanced Custom Fields: Sorting custom columns with custom fields sorts only by date

It appeared it was due to the fact that WordPress doesn’t understand that you need to order by certain post meta unless you specify it. So in my case adding this fixed the sorting issue: add_action( ‘pre_get_posts’, ‘custom_orderby’ ); function custom_orderby( $query ) { if( ! is_admin() ) return; $orderby = $query->get( ‘orderby’); if( ‘featured’ … Read more

How can I show custom fields in the loop only to specific user roles?

You can use current_user_can() and is_user_logged_in() to validate current user: <?php if ( is_user_logged_in() && current_user_can(‘role’) ) : ?> <span style=”font-size:16px”> <strong>Currently reading:</strong> <?php the_field(‘book_name’); ?> (<?php the_field(‘book_year’); ?>)<br/> <strong>Currently seeing:</strong> <?php the_field(‘movie_name’); ?>”><br/> </span> <?php endif; ?> Make sure to change role to your preference and take a look at Codex for more info.