Link meta field to post in query loop

[ad_1]

Thank you @ferdman for your rating and your kind words. I’ll create a snippet code for this use case very soon.

Thanks, Phi.

Hi @ferdman, below is the snippet code for your request, please replace your_image_field_name with your real fieldname.

add_filter(
    'meta_field_block_get_block_content', function ( $content, $attributes, $block, $post_id ) {
        $field_name = $attributes['fieldName'] ?? '';
        if ('your_image_field_name' === $field_name) {
            return sprintf('<a href="https://projectdmc.org/support/topic/link-meta-field-to-post-in-query-loop-2/%1$s">%2$s</a>', get_permalink($post_id), $content);
        }

        return $content;
    }, 10, 4
);

In the future version, I’ll consider adding a ‘Link to post’ setting for some field types like images, text, etc.

Please feel free to contact me if you need help with this block in future.

Phi.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer