• Resolved Derda

    (@derda)


    With all your kind earlier help I still can not get this snippet to work. It should display an alert when i am in edit mode in a CPT called “city” – It should fire when I edit a post or create a new one. Eventually the Alert message shown here would be replaced with some code, where on opening a post for editing, data are pulled from a different CPT and made available in a drop down menu inside a city field. (I am on WP 6.3.1 and ACF Pro latest version.)

    Does someone have an idea where i made a mistake? – Thank you very much.

    // Get the current CPT.
    $current_post_type = get_post_type();
    // Check if the current CPT is the “city” post type.
    if ( $current_post_type == ‘city’ ) {
    // Add the add_action action.
    add_action( ‘edit_post’, function() {
    // Display a custom alert.
    echo ‘<script type=”text/javascript”>’;
    echo ‘alert(“JS alert box inside PHP”)’;
    echo ‘</script>’;
    } );
    }

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Code snippet not working when filtering for a CPT’ is closed to new replies.