Support

Account

Home Forums General Issues How to Target ACF Edit Page?

Unread

How to Target ACF Edit Page?

  • We have a PHP snippet that is being deployed using the Woody Snippets plugin. The code works great and does what it needs to do, which is to populate an ACF text field when the ACF form is saved or updated on the backend.

    But, that snippet is set to “run everywhere” because the only other option within Woody Snippets is to add it to a post or page via a shortcode. We don’t know how to add a shortcode (and have it execute) on an ACF/custom post type form on the back-end.

    The question: How could we edit the snippet (below) to only execute when someone is editing our custom post type on the back-end? We need this because running the snippet everywhere is breaking the Elementor editor, so we’re unable to edit the custom post template.

    Hope that makes sense! Here’s our snippet, if it matters:

    
    // This populates and saves search terms for product landing pages based on what lives in the product tables
    
    function save_search_terms( $post_id ) {
        
        $searchterms = array();
        
        if( have_rows('product_table') ):
        while( have_rows('product_table') ) : the_row();
    
        // Loop over sub repeater rows        
    
            if( have_rows('product_table_products') ):
                while( have_rows('product_table_products') ) : the_row();
    
        // Get sub value
        
        foreach( $tempsearchterms as $tempsearchterm );
            $tempsearchterm = get_sub_field('product_table_product');
                $searchterms[] = $tempsearchterm->part_number . " " . $tempsearchterm->product_name . " " . $tempsearchterm->model_type;
        
                endwhile;
            endif;
        endwhile;
    endif;    
        
        // update field
        
        update_field('search_terms', implode(' ', $searchterms) );
    }
    
    add_action('acf/save_post', 'save_search_terms');
    
    ?>
        <style type="text/css">
    
            #search-terms {
            pointer-events: none;
        }
    
        </style>
    
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.