InsideDarkWeb.com

Access ACF fields within custom preview function?

I’d like to access custom ACF field values from custom_preview() filter?

add_filter( 'preview_post_link', 'custom_preview' );

function custom_preview() {
    // how to access ACF field values here ?
}

WordPress Development Asked on November 21, 2021

1 Answers

One Answer

As documented, the preview_post_link passes the post object as the second parameter. You can use this to get any fields that you might want:

add_filter(
    'preview_post_link',
    function( $preview_link, $post ) {
        $custom_field = get_field( 'custom_field_name', $post );
        
        return $preview_link;
    },
    10,
    2 // MUST be 2 to get the $post parameter.
);

Answered by Jacob Peattie on November 21, 2021

Add your own answers!

Related Questions

How to incluide custom field in WooCommerce email using placeholder

0  Asked on December 8, 2020 by santiago-cuartas-rmrz

 

Adding microdata using Structured Data Markup Helper HTML

1  Asked on December 6, 2020 by desislava-angelova

     

Server timeout error on every weekend

0  Asked on December 6, 2020 by dhaval-joshi

 

How do I make a shortcode to display the shop name on Dokan?

1  Asked on December 5, 2020 by sean-taylor

 

Excess dependencies

1  Asked on December 5, 2020 by lovor

   

A conditional button

1  Asked on December 3, 2020 by aashish-tripathi

       

Visual editor not saving data

0  Asked on December 2, 2020 by jasierok

     

WordPress Register Form

0  Asked on November 30, 2020

   

New post status for custom post type

3  Asked on November 30, 2020 by dclawson

   

Showing related post for custom taxonomy

1  Asked on November 28, 2020 by luca

 

How to hide “Change role to” dropdown on Users admin menu

0  Asked on November 27, 2020 by rijal-islami

     

Colliding custom permalink rules

0  Asked on November 26, 2020 by laurent

   

how to redirect the link to a category in the website

1  Asked on November 26, 2020 by jeline

 

Ask a Question

Get help from others!

© 2021 InsideDarkWeb.com. All rights reserved.