Meta Field Block – Display Custom Fields for ACF, Meta Box and More
This single-block plugin allows you to display custom fields, shortcode as blocks in the Block Editor. It supports custom fields for posts, terms, and users. It can be nested inside a parent block that has postId and postType context, such as Query Loop, WooCommerce Product Collection, Term Query, or used as a stand-alone block. You can display any field whose value can be retrieved by the core API (get_post_meta, get_term_meta, get_user_meta) and is a string or can be converted to a string. To display the field value in the Block Editor, it has to be accessible via the REST API or have the field type set to dynamic. You can also display custom fields created by the Advanced Custom Fields or Meta Box plugin explicitly. It supports all ACF field types and Meta Box field types whose values are strings or can be converted to strings. Some other ACF complex fields such as Image, Link, Page Link, True False, Checkbox, Select, Radio, Button Group, Taxonomy, User, Post Object and Relationship field types as well as Meta Box fields such as Select, Checkbox, Radio, Image, Video, Taxonomy, User, Post field types are also supported in basic formats. This plugin also provides developer-friendly hook APIs that allow you to easily customize the output of the block, display complex data type fields, or use the block as a placeholder to display any kind of content with object_id and object_type as context parameters. An edge case where this block is really helpful is when you need to get the correct post_id in your shortcode when you use it in a Query Loop. In that case, you can set the field type as dynamic and input your shortcode in the field name. The block will display it correctly on both the front end and the editor. Alternatively, if you only want to see the preview of your shortcode in the editor, you can also use this block as a better version of the core/shortcode. To quickly learn how this block displays custom fields, watch the short guide (for MFB version 1.3.4) by Paul Charlton from WPTuts. The video focuses on the Advanced Custom Fields plugin, but you can use a similar approach to display fields from other frameworks like Meta Box. Links Website How it works & tutorials MFB PRO What is the HTML output of a custom field? The HTML output of a custom field on the front end depends on the context of the field. It uses one of these core API functions to get the field value: get_post_meta, get_term_meta, get_user_meta. What is the HTML output of ACF fields? All basic field types that return strings or can cast to strings are supported – The HTML output is from the get_field function. Link type – The HTML output is: {title} There is no rel attribute if the target is not _blank Image type – The HTML output is from the wp_get_attachment_image function. The image size is from the Preview Size setting. True / False type – The HTML output is Yes if the value is true, and No if the value is false. Below is the code snippet to change these text values: add_filter( 'meta_field_block_true_false_on_text', function ( $on_text, $field_name, $field, $post_id, $value ) { return 'Yep'; }, 10, 5 ); add_filter( 'meta_field_block_true_false_off_text', function ( $off_text, $field_name, $field, $post_id, $value ) { return 'Noop'; }, 10, 5 ); Checkbox / Select type – The HTML output is: {item_value} , {item_value} The item_value can be either value or label, depending on the return format of the field. Multiple selected values are separated by ,. Below is the code snippet to change the separator: add_filter( 'meta_field_block_acf_field_choice_item_separator', function ( $separator, $field_name, $field, $post_id, $value ) { return ' | '; }, 10, 5 ); Radio button / Button group type – The HTML output can be either value or label, depending on the return format of the field. Page link type, Post object type – The HTML output for a single-value field is: {title} For a multiple-value field is: {title} {title} Relationship type – The HTML output is: {title} {title} Taxonomy type – The HTML output is: {term_name} {term_name} User type – The HTML output for a single-value field is: {display_name} For a multiple-value field is: {display_name} {display_name} For other complex field types, you can generate a custom HTML output by using the hook: apply_filters( 'meta_field_block_get_acf_field', $field_value, $post_id, $field, $raw_value, $object_type ) Or by using the general hook: apply_filters( 'meta_field_block_get_block_content', $content, $attributes, $block, $object_id, $object_type ) What is the HTML output of Meta Box fields? Similar to ACF fields, all basic fields that return strings or can cast to strings using the function rwmb_get_value are supported. The HTML output of cloneable basic fields is: {item_1_value} , {item_2_value} Use the following hooks to change the tag and the separator: apply_filters( 'meta_field_block_mb_clone_field_item_separator', ', ', $field, $post_id, $field_value ) apply_filters( 'meta_field_block_mb_clone_field_item_tag', 'span', $field, $post_id, $field_value ) Single image types – The HTML output is from the wp_get_attachment_image function. The image size is from the image_size setting. Image list types (Image, Image advanced, Image upload) – The HTML output is: Checkbox / Switch type – Similar to ACF True / False type. Multi-choice types (Select, Select advanced, Button group, Autocomplete, Image select, Checkbox list) – The HTML output is: {item_value} , {item_value} To display the label instead of the value, use this hook: apply_filters( 'meta_field_block_mb_field_choice_item_display_label', false, $field_name, $field, $post_id, $value ) To change the separator, use this hook: apply_filters( 'meta_field_block_mb_field_choice_item_separator', ', ', $file_name, $field, $post_id, $value ) Radio type – The output is the field value by default. To display label or change the separator, use the same hooks as the multi-choice types. Post type – The HTML output for a single-value field is: {title} For a multiple-value field is: {title} {title} Taxonomy, Taxonomy advanced type – The HTML output for a single-value field is: {term_name} For a multiple-value field is: {term_name} {term_name} User type – Similar to ACF User type Video type – The HTML output for a single-value field is: For a multiple-value field is: To display complex field types or change the output of a field, use the hook meta_field_block_get_mb_field or the general hook meta_field_block_get_block_content. Copy & paste snippets When using the meta_field_block_get_block_content hook to customize block content, we recommend selecting dynamic as the field type. This way, both the front end and the editor will show the changes. If you are working with ACF Fields, we suggest using the meta_field_block_get_acf_field hook to modify the field content. Similarly, Meta Box users should use the meta_field_block_get_mb_field hook to modify the content. ACF snippets can also be used with Meta Box fields, but you must use the correct hook name and replace the get_field function with the rwmb_get_value function. How to change the HTML output of the block? Using the meta_field_block_get_block_content hook: add_filter( 'meta_field_block_get_block_content', function ( $block_content, $attributes, $block, $post_id, $object_type ) { $field_name = $attributes['fieldName'] ?? ''; if ( 'your_unique_field_name' === $field_name ) { $block_content = 'new content'; } return $block_content; }, 10, 5); Using the meta_field_block_get_acf_field hook for ACF Fields only: add_filter( 'meta_field_block_get_acf_field', function ( $block_content, $post_id, $field, $raw_value, $object_type ) { $field_name = $field['name'] ?? ''; if ( 'your_unique_field_name' === $field_name ) { $block_content = 'new content'; } return $block_content; }, 10, 5); This basic snippet is very powerful. You can use it to display any fields from any posts, terms, users or setting fields. Please see the details in the below use cases. How to wrap the block with a link to the post within the Query Loop? Using the meta_field_block_get_block_content hook: add_filter( 'meta_field_block_get_block_content', function ( $block_content, $attributes, $block, $post_id ) { $field_name = $attributes['fieldName'] ?? ''; if ( 'your_unique_field_name' === $field_name && $block_content !== '' ) { $block_content = sprintf(' %2$s ', get_permalink($post_id), $block_content); } return $block_content; }, 10, 4); Using the meta_field_block_get_acf_field hook for ACF Fields only: add_filter( 'meta_field_block_get_acf_field', function ( $block_content, $post_id, $field, $raw_value ) { $field_name = $field['name'] ?? ''; if ( 'your_unique_field_name' === $field_name && $block_content !== '' ) { $block_content = sprintf(' %2$s ', get_permalink($post_id), $block_content); } return $block_content; }, 10, 4); This snippet only works with the block that has only HTML inline tags or an image. How to display an image URL field as an image tag? Using the meta_field_block_get_block_content hook: add_filter( 'meta_field_block_get_block_content', function ( $block_content, $attributes, $block, $post_id ) { $field_name = $attributes['fieldName'] ?? ''; if ( 'your_image_url_field_name' === $field_name && wp_http_validate_url($block_content) ) { $block_content = sprintf(' ', esc_attr($block_content)); } return $block_content; }, 10, 4); Using the meta_field_block_get_acf_field hook for ACF Fields only: add_filter( 'meta_field_block_get_acf_field', function ( $block_content, $post_id, $field, $raw_value ) { $field_name = $field['name'] ?? ''; if ( 'your_image_url_field_name' === $field_name && wp_http_validate_url($block_content) ) { $block_content = sprintf(' ', esc_attr($block_content)); } return $block_content; }, 10, 4); How to display multiple meta fields in a block? For example, we need to display the full name of a user from two meta fields first_name and last_name. add_filter( 'meta_field_block_get_block_content', function ( $block_content, $attributes, $block, $post_id ) { $field_name = $attributes['fieldName'] ?? ''; if ( 'full_name' === $field_name ) { $first_name = get_post_meta( $post_id, 'first_name', true ); $last_name = get_post_meta( $post_id, 'last_name', true ); // If the meta fields are ACF Fields. The code will be: // $first_name = get_field( 'first_name', $post_id ); // $last_name = get_field( 'last_name', $post_id ); $block_content = trim("$first_name $last_name"); } return $block_content; }, 10, 4); Choose the field type as dynamic and input the field name as full_name. How to display a setting field? For example, we need to display a setting field named footer_credit on the footer template part of the site. add_filter( 'meta_field_block_get_block_content', function ( $block_content, $attributes, $block, $post_id ) { $field_name = $attributes['fieldName'] ?? ''; // Replace `footer_credit` with your unique name. if ( 'footer_credit' === $field_name ) { $block_content = get_option( 'footer_credit', '' ); // If the field is an ACF Field. The code will be: // $block_content = get_field( 'footer_credit', 'option' ); } return $block_content; }, 10, 4); How to use MFB as a placeholder to display any kind of content? SAVE YOUR TIME WITH MFB PRO To display simple data type fields for posts, terms, and users, you only need the free version of MFB. MFB Pro can save you 90% of development time when working with ACF, or Meta Box complex fields. It achieves this by transforming your ACF complex field types into container blocks, which work similarly to core container blocks. This eliminates the need for creating custom blocks or writing custom code for displaying complex fields. Below are some video tutorials that demonstrate how MFB Pro can help you display complex fields: How to build a post template to display dynamic data without coding How to display ACF Repeater fields as a list, grid, or carousel How to display ACF Gallery fields as a grid, masonry, or carousel The main features of MFB PRO are: Display settings fields. Display ACF advanced layout fields: Group, Repeater, and Flexible content. Display ACF Repeater fields in a carousel layout, which is useful for displaying banner sliders. Display ACF Repeater fields in an accordion layout, which is useful for displaying FAQ pages. Display ACF Relationship and Post Object fields as a Query Loop. Display the ACF Image field as a core image block. Display the ACF Gallery field as an image gallery using grid, masonry, or carousel layouts. Display the ACF File field as a video block, an image block, a button block, or a link. Display the ACF Link field as a button block. Display the ACF URL field as an image block, a button block, a link, a video block, or an embed block. Display the ACF Email field as a button block or a link. Display the ACF oEmbed field as an embed block. Display the ACF Google Map field. All Meta Box field types that correspond to ACF field types support the same Pro features as ACF. Display the Meta Box Group field, similar to the ACF Group field. Display the Meta Box Cloneable Group field as a repeater block, similar to the ACF Repeater field. Supports row, stack, grid or carousel layouts. Display the Meta Box Post field as a Query Loop. Display the Meta Box single image field as an image block, and the image list field as an image gallery using grid, masonry, or carousel layouts. Display the Meta Box File single input field as a video block, an image block, or a button. Display a group field as a details block, and display a repeater or cloned group as an accordion. Set a single image sub-field (ACF Image or Meta Box Image) as the background image of a group field. Display custom fields from a specific post, term or user. Display a taxonomy field as a Terms Query block. Display a repeater or cloned group field as an core/accordion block. Since version 1.5.3, MFB Pro allows you to bind custom fields (ACF, Meta Box, core meta fields, and core settings) directly to core blocks (Heading, Paragraph, Button, Image, Video, Embed, and the background image/video/embed of Cover block). For more complex field types (Group, Repeater, Flexible Content), you can use MFB Pro to display the group as a container. Nested fields can then be displayed using the Sub Field Block, as before, or bound directly to core blocks. If this plugin is useful for you, please do a quick review and rate it on WordPress.org to help us spread the word. I would very much appreciate it. Please check out my other plugins if you’re interested: Content Blocks Builder – Build custom layouts and blocks visually in the Block Editor without needing a code editor, using only core blocks and native Gutenberg features. SVG Block – A block to display SVG images as blocks. Useful for images, icons, dividers, and buttons. It allows you to upload SVG images and load them into the icon library. Icon separator – A tiny block just like the core/separator block but with the ability to add an icon. Breadcrumb Block – A simple breadcrumb …
Top keywords
- field151×5.93%
- block119×4.67%
- display52×2.04%
- content47×1.85%
- acf44×1.73%
- name43×1.69%
- fields41×1.61%
- block content39×1.53%
- meta39×1.53%
- post36×1.41%
- image35×1.37%
- value30×1.18%
Necessary Blocks – Page Builder, Gutenberg Blocks & Patterns
Necessary Blocks, takes Gutenberg’s editing capabilities to the next level with custom blocks and advanced options, allowing you to effortlessly create stunning, high-performance websites. Every block is thoughtfully designed with a focus on performance, accessibility, and flexibility. This toolkit enhances the WordPress block editor, providing functionality that rivals traditional page builders, enabling you to craft visually impressive and engaging content without writing a single line of code. Our user-friendly blocks are designed to simplify your workflow and make your WordPress pages and posts more stunning than ever. Block Animation features inspired from Animate.Style Library. How To Setup Notice Block ? – Video Tutorial More About Necessary Blocks Image Comparison Block – Enhance Storytelling [FREE] The Gutenberg Image Comparison Block allows users to showcase before-and-after images with an interactive slider. Ideal for photographers, designers, and eCommerce, this block improves engagement by letting visitors compare images effortlessly. Fully customizable, it enhancing both UX and SEO. Optimize your visuals and storytelling with this intuitive image comparison tool! 🚀 AI Block [FREE] Necessary blocks for gutenberg blocks now have nice AI Block for writing assistance. You can easilty take help from Artificial Intelligence (AI) openai/chatgpt from your website. From 1.4.7 version it’s command prompt default value will be artical title though you can change its as your wish. Table Of Content Block [FREE] The WordPress Gutenberg Table of Contents block is a feature or plugin-enabled block designed to automatically generate a structured list of headings (H1, H2, H3, etc.) from your post or page content. It provides easy navigation for users by linking directly to different sections of the content. The block is customizable, allowing adjustments. This block enhances user experience and SEO by improving content accessibility and readability. It is often available through plugins like Yoast SEO, Kadence Blocks, or other Gutenberg block libraries. Image Gallery Block [FREE] The Image Gallery Block in WordPress Gutenberg allows you to create a visually appealing gallery of images. Key features include: Multiple Images: Add and display several images in a grid or masonry layout. Customizable Columns: Choose the number of columns for your gallery. Captions: Add optional captions to individual images. Heading: add heading or title for this section. Styling Options: Adjust spacing, borders, and alignment to fit your design. This block is perfect for showcasing portfolios, photo collections, or visual content on your site. Dual Button Block [FREE] The Dual Button Block from Necessary Blocks allows you to create two customizable buttons side by side within a single block. Key features include: Customization Options: Each button can have its own text, link, background color, text color, hover effects, and alignment. Flexibility: Adjustable padding, margin, and border-radius for a tailored design. Responsive Design: Mobile-friendly with responsive layout controls. This block is ideal for creating call-to-action buttons with dual options, like ‘Sign Up’ and ‘Learn More.’ Post Carousel Block [FREE] The Post Carousel Block allows you to display posts in a visually appealing, interactive carousel format. Key features typically include: Customizable Display, Responsive Design, Layout Options: Adjust the number of slides visible at once, spacing, and alignment. Navigation Settings, Styling Options: Customize colors, typography, and spacing to match your site design. This block simplifies showcasing your blog posts or custom content dynamically, enhancing user engagement. Price Box Block [FREE] The Price Box Block is a customizable block designed to showcase pricing details attractively. It is ideal for businesses and services that want to highlight pricing plans, packages, or offers. Key Features: Customizable Layouts: Options to design unique pricing boxes with flexible layouts. Price Emphasis: Highlight prices prominently with adjustable fonts, colors, and sizes. Call-to-Action Buttons: Add clickable buttons for purchasing or exploring more. Feature Lists: Showcase the benefits or features of each pricing tier. Responsive Design: Optimized for viewing across devices. Style Adjustments: Tailor colors, borders, backgrounds, and typography without coding. It simplifies creating professional and visually appealing pricing sections for websites. Accordions Block [FREE] The Accordions Block is a collapsible content block designed to organize and display content in an interactive, space-saving way. It allows users to group related information under expandable headers, improving readability and user experience. Key Features: Accordion Items: Each accordion block consists of individual items, each with a title (header) and content section. Collapsible Design: Users can expand or collapse content sections, showing only what they need. Responsiveness: Automatically adapts to various screen sizes. It’s ideal for FAQs, tutorials, or sections where compact content presentation enhances usability. Pros and Cons Block [FREE] The WordPress Gutenberg Pros and Cons block is a useful feature for creating comparison-style content in an engaging, visually appealing manner. Here’s why it’s important: Pros: User-Friendly Layout: Enables clear organization of positive and negative points. Visually Appealing: Enhances readability with structured blocks for pros and cons. SEO-Friendly: Helps present content in a way that improves user experience and engagement, which can boost search rankings. Customizable: Allows flexibility in design and formatting to match site branding. Efficient Content Creation: Saves time by offering a predefined format. Cons: Limited Customization: Built-in designs may not meet all styling needs without custom CSS. Dependency on Gutenberg: Requires familiarity with the block editor, which might not appeal to all users. Performance Issues: Overloading a page with blocks can sometimes affect site performance. This block is ideal for bloggers, reviewers, and marketers seeking a streamlined approach to presenting balanced opinions. Team Card Block [FREE] The Team Card Block in Gutenberg is a customizable block designed to showcase team members or individuals. It includes features like: Profile Image, Name and Role, Description, Social Media Links. Custom Styling: Adjust colors, and borders to match your site’s branding. This block is ideal for creating ‘About Us’ pages or highlighting contributors on your website. Rating Block [FREE] The Rating Block in Gutenberg is a versatile block designed for displaying ratings or reviews on your website. Key features include: Star Ratings: Display ratings using stars (e.g., out of 5 or 10). Static Ratings: Show fixed ratings to describe reviews. Styling Options: Customize colors, size, alignment, and overall design. It is perfect for product reviews, testimonials, or content evaluation. Countdown Block [FREE] The Countdown Block in Gutenberg is a block designed to display a countdown timer for events or promotions. Key features include: Set Countdown Date and Time: Specify the target date and time for the countdown to end. Customizable Display: Show days, hours, minutes, and seconds in various formats. Use Cases: Ideal for event launches, sales, product releases, or any time-sensitive content. This block adds urgency and engagement to your website. Notice Block [FREE] The Notice Block is used to display attention-grabbing messages or alerts on your site. It is typically designed to highlight important information such as: Announcements: Display updates or news. Warnings: Highlight critical alerts or cautions. Tips: Share helpful advice or guidance. Customizable Appearance: Adjust colors, icons, and typography to align with the message’s importance and your site’s design. This block is ideal for emphasizing content that needs user attention. Article Block [FREE] The Article Block is a versatile block designed for presenting articles, blog posts, or featured content in a structured and visually appealing way. Key features include: Title and Excerpt: Display the article’s headline and a summary or excerpt. Featured Image: Option to showcase an image alongside the text. Table Block [FREE] The Table block is based on the default Table block in Gutenberg. This improved version of the block has tons of extra table features including advanced styling such as margin, padding, alignment, colors and more. Videos Block [FREE] The Video block is based on the default Video block in Gutenberg. This improved version of the block has tons of extra video settings features including advanced styling such as speed, margin, padding, alignment, colors and more. The Buttons Block [FREE] In WordPress Gutenberg is a versatile block used to add clickable buttons to posts or pages. It allows users to: Add customizable buttons with text and links. Style buttons with various options, including colors (text, background), border-radius, and alignment. Use pre-defined theme styles or set custom dimensions and styles. Add dynamic link settings, like opening in a new tab or adding nofollow attributes. It’s commonly used for CTAs (Call-to-Actions), navigation links, or promoting actions like “Buy Now” or “Learn More.” How To Setup Button Block ? – Video Tutorial NECESSARY BLOCKS USE CASE Web Developers Looking to streamline your website-building process without diving into coding? Necessary Blocks simplifies the task! With its powerful features, you can design stunning layouts and customize elements effortlessly, no coding required. Website Owners Creating a professional website for your business is now simpler than ever with Necessary Blocks. Select from a range of pre-built Starter Templates and tailor them to fit your branding and content seamlessly. Say goodbye to expensive web development and hello to an impressive online presence. Content Creators Transform your website posts into captivating experiences with Necessary Blocks’ dynamic blocks. Incorporate striking images, compelling call-to-actions, interactive timelines, and seamless social sharing features. Make your content shine and keep your readers coming back for more. SEO Specialists Necessary Blocks includes schema markup features such as Accordion blocks, testimonials, and Table of Content blocks to enhance your website’s rankings and improve search engine visibility. Its lightweight, optimized code ensures top-notch performance. Get ready to climb the search results and stand out online! WooCommerce Developers Create visually stunning star ratings and reviews, and display pricing information with ease. Necessary Blocks empowers you to craft an online store that attracts customers and drives conversions. Freelancers Streamline your workflow and save valuable time with Necessary Blocks. Use pre-built Starter Templates to quickly build websites for your clients and customize them to their specific needs. It’s the ultimate toolkit for efficient and impressive freelance work. Non-Profit Organizations Create visually compelling websites to highlight your cause, share inspiring success stories, and collect donations. Necessary Blocks’ image blocks, forms, testimonials, and social sharing options help you engage your audience and promote your mission effectively. Corporate Organizations Create visually compelling websites to highlight your cause, share inspiring success stories, and boost sells. Necessary Blocks’ image gallery blocks, testimonials, and social sharing options help you engage your audience and promote your business effectively. Gutenberg Users With its user-friendly interface, pre-designed Starter Templates, and comprehensive tutorials, Necessary Blocks makes website creation a breeze. No coding skills are required! Build professional-looking websites and impress everyone with your online presence. Flipbox Block is a WordPress block that allows to create interactive content boxes with flipping animations. It typically includes two sides: a front and a back, where you can add text, images, icons, or other content. Users hover over or click the box to trigger the flip animation, revealing the back content. Customization: Choose colors, fonts, and animations. Interactive Effects: Hover or click triggers the flip. Content Versatility: Supports various media and text combinations. About the Necessary Blocks Team Hello! We are Necessary Blocks, a passionate team based in the vibrant city Dhaka. Every day, we’re inspired by the breathtaking beauty of our surroundings—the ever-changing hues of the sky, the rivers that cradle our city, and the diverse cultures and languages of the people who call Dhaka home. This rich tapestry of life keeps our creativity flowing and ensures we’re never bored! When we’re not writing code or assisting users, you’ll often find us wandering through the woods, exploring nature, and enjoying the thrill of getting a little lost. We believe in living life to the fullest and making every day count. If you have any comments or questions, feel free to reach out through our contact form—we’d love to hear from you! As a brand, we specialize in creating clean, professional-grade WordPress tools that empower everyone to build beautiful websites with ease. Our name reflects our mission: a nod to “coders’ time,” celebrating the coders who build tools for people who don’t need to code themselves. NEED SUPPORT ? We recognize the importance of providing a high-quality product supported by a caring and dedicated team. We’re here to address your questions and help you maximize the benefits of our plugin. Need assistance? We’re only a click away! CONTACT WITH OUR TEAM Facebook: Coders Time X ex Twitter: Coders Time Documentation : Necessary Blocks Live Chat : Live Chat WhatsApp : WhatsApp