Meta Key Value in current-user-only loop
There is no $post var local to your function, you need to use global $post first, or get_the_ID(). get_post_meta( get_the_ID(), ‘_cf_address’, true );
There is no $post var local to your function, you need to use global $post first, or get_the_ID(). get_post_meta( get_the_ID(), ‘_cf_address’, true );
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
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
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
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
If I understand it right your workflow is that you query posts (implicitly via normal WP mechanics), then display data from external database for them, but want to sort based on external data. This isn’t trivial (without mirroring you don’t want to do), since WP relies primarily on SQL over its own data for sorting. … Read more
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.
If i create an array and convert it into JSON, will it be faster if i call 12 meta fields one by one or call the JSON, parse it and then have the variables? Virtually no difference. The meta API means that all meta keys/fields/values are pulled into memory from the database at most once … Read more
This is how meta_key/_values work. How you store your values is case sensitive. Example meta_key = “foo’ and meta_value=”Bar” Would return the result you are looking for: $posts = new WP_Query( ‘post_type=post&meta_key=foo&meta_value=Bar’ ); Would not return the result you are looking for: $posts = new WP_Query( ‘post_type=post&meta_key=foo&meta_value=bar’ ); However it does appear that your database … Read more
Are you outputting the saved data to the edit post page before saving the post? If not you may be getting a empty $_POST[‘collection-topics’] data and then saving empty or null data. I would do a check before doing add_post_meta() if ( empty($_POST[‘collection-topics’]) ) return;