ACF custom block get_field() shows null on front-end? [closed]
ACF custom block get_field() shows null on front-end? [closed]
ACF custom block get_field() shows null on front-end? [closed]
Modify the following line in your function: $value = number_format(floatval($value), 2); To include another two arguments from the number_format() function – namely the decimal separator (set to a dot) and the thousands separator (set to an apostrophe) $value = number_format(floatval($value), 2, “.”, “‘”); So in total this line says: format the number (after floating it … Read more
The ACF functions accept a second argument which is the ID of the page you wish to retrieve the fields from. See the code examples in documentation. $page_id = 120; if( get_field( ‘treatments’, $page_id ) ): while( has_sub_field( ‘treatments’, $page_id ) ): // the_sub_field and get_sub_field don’t need a post id parameter the_sub_field(‘image’ ); the_sub_field(‘description’ … Read more
You’re running the query twice and passing the result of the first query to the second query. Give this a try. You might also consider using the update function from wpdb instead of running an arbitrary query because it doesn’t look like you’re doing any data sanitization or nonce checks. If you do want to … Read more
Just for the sake of closing the question: <?php if(get_sub_field(‘asset_type’) == “Image”) { ?> <div><?php the_sub_field(‘image_asset’); ?></div> <?php } ?> <?php if(get_sub_field(‘asset_type’) == “Video”) { ?> <div><?php the_sub_field(‘video_asset’); ?></div> <?php } ?>
ACF uses get_field so you can get the value before you output it. Just make sure you have a $total_credit variable before you start the loop and just add to it. When the loop is done print the total to your table. NOTE: This is just pseudo code, so don’t copy/paste this, just use it … Read more
Answering my own question again. 😛 I finally found this Gist that lets me get and set array variables via dot notation: https://gist.github.com/elfet/4713488 So I included the DotNotation class and now my code looks like this (skipping all sorts of error checking here) : $fieldmap_string = ‘key1.key2.key3.etc’; $current_page_content = get_field(‘page_content’, $source_post_id); $parsed_current_content = new DotNotation($current_page_content); … Read more
The issue is with ACF as discussed here along with a solution: https://support.advancedcustomfields.com/forums/topic/how-to-use-wp-term-meta-on-acf-the-easy-way/ Courtesy of various posters there, the code I added to mu-plugins is: function acf_update_term_meta($value, $post_id, $field) { $object = get_queried_object(); $term_id = intval(filter_var($post_id, FILTER_SANITIZE_NUMBER_INT)); if (!isset($object->taxonomy) || !isset($object->term_id) || $term_id != $object->term_id) { // the current object is not a term return … Read more
Since you already mentioned that you are using these codes, I assume they both work for you. Now, I have combined them for you into a single function that updates the metadata after a post is published: function set_date_difference($post_id){ // Get the value of the first field $date1 = get_field(‘date_start’, $post_id, false ); $date1 = … Read more
Create a page named as your archive, add blocks there. In archive-name.php please add: <?php get_header(); $page_id = get_post( 57 ); $page = apply_filters( ‘the_content’, $page->post_content ); echo $page; ?> <?php get_footer(); Replace ’57’ with your page ID. Now you can manage content of archive page directly from Pages.