Using ACF on Posts Page
Have you set a static page as your blog home page? You can do this under Settings > Reading. Otherwise get_option(‘page_for_posts’) won’t work.
Have you set a static page as your blog home page? You can do this under Settings > Reading. Otherwise get_option(‘page_for_posts’) won’t work.
If you expecting a number as a value you can set the type parameter to NUMERIC. Otherwise 0 is evaluated to false. Then you can use IN comparison if you only want a set range. $test_query = new WP_Query( [ ‘meta_query’ => [ [ ‘key’ => ‘test_key’, ‘value’ => [ 0, 1 ], ‘compare’ => … Read more
First thing to fix is the_sub_field(‘year’), as it will print out your year string instead of passing it to your variable. Instead, I think you want $year = get_sub_field(‘year’); And, to answer your question, it’s easy to convert a string to an int by passing (int) in front of the item. $year = (int)get_sub_field(‘year’);
I see you’ve found your own answer, but I wanted to offer some advice for making your code a little more succinct. <?php // Different versions of a number $unformatted = get_field(‘paid_attendance’); $cleaned = str_replace(‘,’, ”, $unformatted); // Remove commas from string $integerValue = absint( $cleaned ); // Convert to absolute integer. $floatValue = number_format($cleaned, … Read more
There’s a plugin with an additional field typ with which you can force the user to crop the image to a specific size: https://github.com/andersthorborg/ACF-Image-Crop It’s not clear if it’s still under active development so you’d have to test it with newer ACF versions. There’s also one with aspect ratios instead of sizes if you need … Read more
Solved!!! $post_id = $pid; needs to be $post_id = “user_{$pid}”; Seems pretty obvious now as the id could be for anything. Chris
What “return format” do you have set in ACF for the date field? Sorting by numbers produces unexpected results when you use “d/m/Y” or “m/d/Y”. If you instead choose “Ymd” as in “20180221” for the return format, you’ll get an integer that’s sortable in the expected way.
Nevermind, got it – it’s simply {{ group }} when calling the value! {% for contact in mc.contacts %} {% for group in contact.groups %} {{ group }} {% endfor %} {% endfor %}
You can use the global $wp_locale to get the month translated in each language. You just need to get the month number (01 to 12) from the Acf field. You have the functions in the WP_Locale class get_month() and get_month_abbrev() global $wp_locale; $month = $wp_locale->get_month(04); // Output april in english $month_abbrev = $wp_locale->get_month_abbrev($month); // Output … Read more
You’re missing quotes around the content of innerHTML. If correctoutput is <div></div>, then you’re script looks like this: $(‘#correcto’).innerHTML(<div></div>); Which is invalid, because you’re missing quotes. innerHTML needs a string, which is in quotes in JavaScript. That first < is where your error is coming from. So you need to do this: $(‘#correcto’).innerHTML(‘<?php the_field(‘correctoutput’); ?>’); … Read more