🎨 Canto ACF Debug

This tool helps diagnose issues with Canto ACF integration.

❌ ACF Plugin Not Active: Advanced Custom Fields plugin is not active or not installed.

✅ ACF Plugin Active: Advanced Custom Fields is available.

🔍 Test Specific Post

Post ID

🎯 Recent Canto Attachments

show_canto_attachments(); ?>

📝 ACF Fields for Post ID:

show_acf_fields($post_id); ?>

📎 Attachment Details:

show_attachment_details($attachment_id); ?>

📋 Recent Posts with ACF Fields

show_recent_posts_with_acf(); ?>

💡 Common Solutions

Example Theme Code:

<?php
// Add this to your theme template (single.php, page.php, etc.)

// Display image field
$image = get_field('your_image_field_name');
if ($image): ?>
    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>">
<?php endif; ?>

// Display gallery field
$gallery = get_field('your_gallery_field_name');
if ($gallery): ?>
    <div class="gallery">
        <?php foreach ($gallery as $image): ?>
            <img src="<?php echo $image['sizes']['medium']; ?>" alt="<?php echo $image['alt']; ?>">
        <?php endforeach; ?>
    </div>
<?php endif; ?>
'attachment', 'meta_key' => '_canto_asset_id', 'posts_per_page' => 10, 'orderby' => 'date', 'order' => 'DESC' )); if ($attachments) { echo ''; echo ''; echo ''; foreach ($attachments as $attachment) { $canto_id = get_post_meta($attachment->ID, '_canto_asset_id', true); $url = wp_get_attachment_url($attachment->ID); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
IDTitleCanto IDURLPreviewActions
' . esc_html( $attachment->ID ) . '' . esc_html( $attachment->post_title ) . '' . esc_html( $canto_id ) . 'View File'; if (strpos($attachment->post_mime_type, 'image/') === 0) { echo ''; } else { echo '📄 ' . esc_html( $attachment->post_mime_type ); } echo 'Details
'; } else { echo '

No Canto attachments found. Try inserting an image via ACF first.

'; } } private function show_acf_fields($post_id) { if (!function_exists('get_field_objects')) { echo '

ACF plugin not available.

'; return; } $post = get_post($post_id); if (!$post) { echo '

Post not found.

'; return; } echo '

Post: ' . esc_html( $post->post_title ) . ' (' . esc_html( $post->post_type ) . ')

'; echo '

Status: ' . esc_html( $post->post_status ) . '

'; echo '

Frontend URL: ' . esc_url( get_permalink($post_id) ) . '

'; $fields = get_field_objects($post_id); if ($fields) { foreach ($fields as $field_name => $field) { echo '
'; echo '

' . esc_html( $field['label'] ) . ' (' . esc_html( $field_name ) . ')

'; echo '

Type: ' . esc_html( $field['type'] ) . '

'; echo '

Value:

'; echo '
' . esc_html( print_r($field['value'], true) ) . '
'; if ($field['type'] === 'image' && $field['value']) { echo '

🖼️ Image Display Test:

'; if (is_array($field['value']) && isset($field['value']['url'])) { echo ''; echo '

✅ Image array format - working correctly

'; } elseif (is_numeric($field['value'])) { $image_url = wp_get_attachment_url($field['value']); if ($image_url) { echo ''; echo '

✅ Attachment ID format - working correctly

'; } else { echo '

❌ Could not get image URL for attachment ID: ' . esc_html( $field['value'] ) . '

'; } } } echo '

💻 Template Code:

'; echo '
';
                if ($field['type'] === 'image') {
                    echo esc_html( '

    <?php echo $' . $field_name . '[\'alt\']; ?>
' );
                } else {
                    echo esc_html( '

    
' );
                }
                echo '
'; echo '
'; } } else { echo '

No ACF fields found for this post.

'; } } private function show_attachment_details($attachment_id) { $attachment = get_post($attachment_id); if (!$attachment || $attachment->post_type !== 'attachment') { echo '

Attachment not found.

'; return; } $url = wp_get_attachment_url($attachment_id); $file_path = get_attached_file($attachment_id); $canto_id = get_post_meta($attachment_id, '_canto_asset_id', true); $canto_data = get_post_meta($attachment_id, '_canto_asset_data', true); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
WordPress ID' . esc_html( $attachment_id ) . '
Title' . esc_html( $attachment->post_title ) . '
MIME Type' . esc_html( $attachment->post_mime_type ) . '
URL' . esc_url( $url ) . '
File Path' . esc_html( $file_path ) . '
File Exists' . ( file_exists($file_path) ? '✅ Yes' : '❌ No' ) . '
Canto Asset ID' . ( $canto_id ? esc_html( $canto_id ) : 'Not from Canto' ) . '
'; if (strpos($attachment->post_mime_type, 'image/') === 0) { echo '

🖼️ Image Preview:

'; echo ''; } if ($canto_data) { echo '

📋 Canto Metadata:

'; echo '
' . esc_html( print_r($canto_data, true) ) . '
'; } } private function show_recent_posts_with_acf() { $posts = get_posts(array( 'post_type' => array('post', 'page'), 'posts_per_page' => 10, 'meta_query' => array( array( 'key' => '_', 'value' => 'field_', 'compare' => 'LIKE' ) ) )); if ($posts) { echo ''; echo ''; echo ''; foreach ($posts as $post) { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
IDTitleTypeStatusActions
' . esc_html( $post->ID ) . '' . esc_html( $post->post_title ) . '' . esc_html( $post->post_type ) . '' . esc_html( $post->post_status ) . ''; echo 'Debug '; echo 'Edit '; echo 'View'; echo '
'; } else { echo '

No posts with ACF fields found.

'; } } } // Initialize the debug admin page new Canto_Debug_Admin();