Custom meta box repeated field

I want to add a field in my custom meta box, same as below, but not for tags. How can I repeatedly take more inputs in the same field? Here is my code added to functions.php: function dikka_cmb_meoxes( array $meta_boxes ) { $prefix = 'dikka_'; $meta_boxes['details_meox'] = array( 'id' => 'details_meox', 'title' => __( 'Porject Details', 'dikka' ), 'pages' => array( 'portfolio', ), // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on …
Category: Web

How using the Meta Box plugin, to filter posts by the value of a post type field?

I'm using the Meta Box plugin to create custom post types and fields. There is a record type teachers, and I'm trying to display the lessons associated with him on the page of a certain teacher. The code looks like this: $queryArgs = array( 'post_type' => 'lessons', 'order' => 'ASC', 'posts_per_page' => -1, 'orderby' => 'meta_value', 'meta_key' => 'lessons_teacher', 'compare' => 'LIKE', 'meta_query' => [ [ 'key' => 'post_name', 'value' => 'john-smith', ] ] ); and here it is not …
Category: Web

Found 2 elements with non-unique id (#_ajax_nonce) and (#_wpnonce)

I am developing custom theme from scratch and creates a custom post type and getting this warning while editing custom post type. I also design custom Meta box with two input fields and using nonce in it. Any help removing these warning? Here is code of custom metabox in functions.php //Custom Metabox function register_book_meta_box(){ add_meta_box('book_meta_box_id', 'Book Detail','design_book_meta_box','books','advanced','high'); } add_action('add_meta_boxes','register_book_meta_box'); function design_book_meta_box($post){ wp_nonce_field(basename(__FILE__),'book_cpt_nonce') ?> <div> <label for="book-author">Author Name  </label> <input type="text" name="book-author" placeholder="Author Name" value="<?php echo get_post_meta( $post->ID, 'book-author-key', true );?>"> </div> …
Category: Web

Why is $_POST empty when saving custom Meta Box?

I'm creating a Meta Box in my custom Plugin where the Administrator can select which users can view a certain post based on their roles. When I select the role and save the meta box content by clicking on the Update button, nothing gets saved because both $_POST['metabox_nonce'] and $_POST['membership_level'] are empty. Why is the form not sending any data? Thank you so much for your help. This is my code: add_action( 'add_meta_boxes', array($this, 'add_italianglot_membership_box' )); add_action( 'save_post', array( $this, …
Category: Web

Add URL to selected post in meta box

How can I change this code $posts = get_posts(array('post_type'=> 'lesson', 'post_status'=> 'publish', 'suppress_filters' => false, 'posts_per_page'=>-1)); //here you add the HTML of the dropdown you add something like echo '<p>Select the lesson: <select name="_dappcf_i_dropdown" class="widefat" style="width:170px" >'; foreach ($posts as $post) { echo '<option value="', $post->ID, '"'; if ($my_dropdown == $post->ID){echo ' selected="selected"';} echo '>'.$post->post_title.'</option>'; } echo '</select>'; } to echo the title of the selected post in page template with the URL of of SELECTED post(the title should be …
Category: Web

Include custom fields into the content of a regular page

Here's my setup: Parent "Gallery" page: _regular page, not custom type or anything _ Several "Project" child pages (could be as few as 1, unlimited number): also normal pages Child pages will either have meta boxes or custom fields for entering stuff into my pre-formatted areas. I don't care if it's meta boxes or custom fields, whatever is figure-outable! I'm using standard WP-provided code to show Child page titles and the_content on the Parent page. <?php $mypages = get_pages( array( …
Category: Web

Repeatable field within repeatable group of fields

Compounding on Saving metabox repeatable fields ... I've created a metabox with a series of fields that are repeatable. However, within those fields, I'd like to create another field named Choices and make that repeatable within each grouping. I was able to setup the additional field and repeat it, but have no idea how to save the value of the new repeatable field. The new field that I was trying to create is within the commented portions of the code …
Category: Web

Finding the screen id of a page generated with add_menu_page

I'm at a basic level of WordPress + PHP and I'm trying to build a pretty simple plugin. I've set up the plugin correctly, and the plugin page is generated with function wpplugin_settings_page() { add_menu_page( 'Modal Generator', 'Modal Generator', 'manage_options', 'modal-slug', 'wpplugin_settings_page_markup', 'dashicons-format-gallery', 100 ); } Whereas wpplugin_settings_page_markup is a function that generates my HTML on the plugin page. I copy-pasted a code to create/generate metaboxes and they work great. I can get them to show on posts & pages …
Category: Web

meta_query with meta values as serialize arrays

I'm working on a project in which I'm creating a custom post type and custom data entered via meta boxes associated with my custom post type. For whatever reason I decided to code the meta boxes in such a way that the inputs in each metabox are part of an array. For instance, I'm storing longitude and latitude: <p> <label for="latitude">Latitude:</label><br /> <input type="text" id="latitude" name="coordinates[latitude]" class="full-width" value="" /> </p> <p> <label for="longitude">Longitude:</label><br /> <input type="text" id="longitude" name="coordinates[longitude]" class="full-width" value="" …
Category: Web

Displaying Meta Box Image

I have some problems displaying info from my custom meta box in my custom post type single. I'm using Reusable Custom Wordpress Meta Boxes by Tammy Hart. I'm able to display the textfields using this: <?php echo get_post_meta($post->ID, $prefix.'hjemmeside', true); ?> But I can't get the image to display, instead DEBUG is telling me that it is an "Undefined variable: post_meta_data in". Currently I'm using this script: <?php $custom_image = $post_meta_data['image'][0]; echo wp_get_attachment_image($custom_image, 'thumbnail'); ?> Is this wrong? ID for …
Category: Web

Create Meta boxes dynamically

I followed and created a meta box using all code from this question here: Create more Meta Boxes as needed Basically only two fields are created when you click on Add track button: Song title field - Track number field But I need something like that: Add album name button - add a field for a album name; Add track number button - add a field for track number; This is my code right now: add_action( 'add_meta_boxes', array( $this, 'dynamic_add_custom_box' …
Category: Web

How to avoid saving empty data to sql while using add_meta_box

I'm trying not to save empty data (null) while using add_meta_box function. My code is /** * Register meta boxes. */ function hcf_register_meta_boxes() { add_meta_box( 'hcf-1', __( 'Hello Custom Field', 'hcf' ), 'hcf_display_callback', 'post' ); } add_action( 'add_meta_boxes', 'hcf_register_meta_boxes' ); /** * Meta box display callback. * * @param WP_Post $post Current post object. */ function hcf_display_callback( $post ) { include plugin_dir_path( __FILE__ ) . './form.php'; } /** * Save meta box content. * * @param int $post_id Post ID …
Category: Web

Wrong post ID in meta box callback

I trying to get the ID of the post on edit page but its displaying the wrong ID Custom Post: register_post_type( 'projetos', array( 'description' => 'Projetos do Scan' ,'exclude_from_search' => false ,'public' => true ,'publicly_queryable' => true ,'show_ui' => true ,'show_in_menu' => true ,'query_var' => true ,'rewrite' => array( 'slug' => 'projeto' ) ,'capability_type' => 'post' ,'has_archive' => true ,'menu_position' => 20 ,'supports' => array( 'title', 'editor' ) ,'hierarchical' => true ,'labels' => array( 'name' => _x( 'Projetos', 'post type …
Category: Web

Allow HTML in Custom Metabox area

I know there are many questions related to my question, but sincerely i was unable to get solution. My question is simple, how can i allow html in textarea in custom metabox on post. So far i have created this code of adding meta boxes. add_action( 'add_meta_boxes_post', function ( $post ) { if ( $post->_wp_page_template === 'page-templates/skyscraper-post.php' ) { add_meta_box( 'sky_post_excerpt', 'SkyScraper Post Excerpt and Links', 'sky_post_excerpts', 'post', 'advanced', 'high' ); } }); add_action( 'save_post', 'post_meta_box_save' ); function sky_post_excerpts() { …
Category: Web

show a specific metabox dependent on the page template

For a few days I am trying to show a specific metabox dependent on the page template. I can do it but my problem is when I have selected a page template and hit the update button then the metabox does not show. metabox is showing when I reload the page. Actually, I want when I will hit the update button then the metabox will be shown. please help me. Note: I use CMB2 for meta boxes. I tried this …
Category: Web

Add custom buttons with custom actions in Edit Post screen in WordPress?

I am creating something for a client and I have a Class that I created with a Custom Post Type called 'PuSH Feeds' and when the user adds a new post and publishes it they can then click on one of two buttons that I have in the Custom Meta Box. One button is for 'Subscribe' and the other for 'Unsubscribe'. I am using the save_post action hook and testing if the $_POST global has that 'pushfeed-subscribe' or 'pushfeed-unsubscribe' and …
Category: Web

Adding metabox to wordpress plugins menu page

Now I am building a wordpress plugin. I need to add a metabox to the admin submenu page. I tried like this below, add_action( 'add_meta_boxes', 'add_meta_boxs'); function add_meta_boxs() { add_meta_box( 'my-meta-box-id', 'My First Meta Box', 'meta_box', 'myContactForm', 'normal', 'high' ); } I created a submenu page: add_submenu_page( 'myForm', 'Add New' , 'Add New', 'manage_options', 'newForm', 'newform_page'); function newform_page() { <div class="form-container-2"> <?php do_meta_boxes('myContactForm', 'normal', null); ?> </div> } Here "myContactForm" is a custom post type. Meta box was created in …
Category: Web

Adding to an array & passing it through do_action/apply_filters

For exercise I am working through a PHP class to add meta boxes I found on GitHub. I just copied the code and now I am playing around with it to understand it. It works like this: The file containing the class is included on init. Inside that file, but outside the class, an empty array $meta_boxes is initialized. After that, a custom action is executed, using apply_filters. My guess is apply_filters is used instead of do_action because the latter …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.