Forum Replies Created
-
AuthorPosts
-
March 22, 2019 at 3:22 PM in reply to: ✅Fields not showing: Warning: Invalid argument supplied for foreach() #13863
Anh Tran
KeymasterYes, of course, I will.
March 22, 2019 at 11:19 AM in reply to: Cannot get custom fields to display on a taxonomy page #13856Anh Tran
KeymasterHi Toomas,
Can you
var_dump( $term_id )to see if that's the correct ID of the current term?Anh Tran
KeymasterI got it. Let me summarize the process flow that you're trying to do:
- Getting settings
- Use the settings to register a CPT
- Register custom fields for the CPT
If you don't do the step 3, then you can do both steps 1+2 at priority 30. The CPT will be registered without any problem.
A better solution is getting the settings with
get_option, like this:$option = get_option( 'multi_tema_privado' ); $mb_activacion_articulo = $option['modulo_articulos_activacion'] ?? ''; if ($mb_activacion_articulo == 1) $show_articulo = true; $mb_slug_articulo = $option['modulo_articulos_slug'] ?? '';Anh Tran
KeymasterHi Sean,
You're using field ID
coaching_lesson_summaryin the helper function. But the real ID is$prefix . 'coaching_lesson_summary', which isprefix-coaching_lesson_summary. So, your code should be:$value = rwmb_meta( 'prefix-coaching_lesson_summary' ); echo $value;March 21, 2019 at 5:11 PM in reply to: ✅Fields not showing: Warning: Invalid argument supplied for foreach() #13840Anh Tran
KeymasterHi Ale, can you
var_dump( $image_fields )to see what values it has?Anh Tran
KeymasterI've just tested again on Firefox and Chrome and couldn't replicate the bug. Would you mind giving me the code for the
sliderfield?Anh Tran
KeymasterHi, thanks for your feedback. I'm checking it now.
March 20, 2019 at 3:27 PM in reply to: ✅Fields not showing: Warning: Invalid argument supplied for foreach() #13813Anh Tran
KeymasterHi Ale, can you post the code you use on those locations?
Anh Tran
KeymasterHi Jiro, you're right about the missing
userin theupdate_user_metacall. I've just added that fixed.Regarding the var_dump, it's not strange as the field registry (where all fields are stored) is structured like this:
object_type specific_type field 1 field 2For posts,
object_typeispostandspecific_typeis post type. For terms, it'stermand taxonomy. For users, as there's no specific type, we useuseranduser.Anh Tran
KeymasterHi, you can do like this with Meta Box:
First, separate the code that get list of BuddyPress groups into a function (it's a good practice to keep this logic away from plugins):
function prefix_get_bp_groups() { global $wpdb; $table = $wpdb->prefix."bp_groups"; $groups = $wpdb->get_results( "SELECT id,name FROM $table" ); if ( !empty( $groups ) ) { return []; } $return = []; foreach( $groups as $group ) { $return[$group->id] = $group->name; } return $return; }Then register a meta box with the following code:
add_filter( 'rwmb_meta_boxes', 'prefix_register_meta_boxes' ); function prefix_register_meta_boxes( $meta_boxes ) { $meta_boxes[] = [ 'title' => 'Your title', 'fields' => [ [ 'id' => 'your_key', 'name' => 'BuddyPress group', 'type' => 'select', 'options' => prefix_get_bp_groups(), // THIS ], ], ]; return $meta_boxes; }Anh Tran
KeymasterHi, please change the priority in the
add_actionfrom 0 to something greater than 20. Meta Box plugin register fields at priority 20 (to make sure all custom post types and custom taxonomies are available when they also use theinithook with priority 10). So, changing it to a number greater than 20 makes the meta boxes and fields available and you're able to use the helper functions to get the value.Anh Tran
KeymasterI'm afraid it's not possible. I'll see if we can add that to the plugin. This is a good idea.
March 19, 2019 at 5:04 PM in reply to: disable user from submitting mobile and email in text area using frontend form #13793Anh Tran
KeymasterHi,
I think this can be done with custom JavaScript only. So you need to enqueue your JS file on the page that has the form, then in the code, when the form is being submitted, check if the value of the textarea is a mobile number or email address. If it is, then return
falseto prevent the submission.This is a pseudo-code that might give you some idea:
jQuery( function( $ ) { $( '.your-form' ).on( 'submit', function() { var value = $( '#your-field' ).val(); if ( checkIfIsMobileNumberOrEmail( value ) ) { return false; } } ); } ); -
AuthorPosts