Forum Replies Created
-
AuthorPosts
-
Long Nguyen
ModeratorHi,
You can use the function to get the user login name as the code that registers the meta box to add the user name to the file name.
function my_unique_filename_callback( $dir, $name, $ext ) { $current_user = wp_get_current_user(); $user_login = $current_user->user_login; $name = 'emargements_' . $user_login . '_' . $name; return $name . $ext; }March 9, 2022 at 12:40 PM in reply to: Gravity Form Advanced Post Creation and MB Custom Table #34420Long Nguyen
ModeratorHi,
With this hook, you can call the public API of MB Custom Table extension to add the field value to the custom table. For example:
add_action( 'gform_advancedpostcreation_post_after_creation', 'after_post_creation', 10, 4 ); function after_post_creation( $post_id, $feed, $entry, $form ){ $data = [ 'field_1' => 'value 1', 'field_2' => 'value 2', 'field 3' => ['one', 'two', 'three'], ]; \MetaBox\CustomTable\API::add( $post_id, $table, $data ); }Read more on the documentation https://docs.metabox.io/extensions/mb-custom-table/#api
https://docs.gravityforms.com/gform_advancedpostcreation_post_after_creation/Long Nguyen
ModeratorHi Cees,
Please be aware that
siteis an object,contactandct_locatiein this case is the property of that object.If you want to pass the field ID as a string, you can add just
ct_locatie{{ mb.map( 'ct_locatie', '100%', '480px', '14', '', 'Solexverhuur Woudenberg', 'Hier vindt je onze locatie' ) }}Long Nguyen
ModeratorHi,
To get the term meta value, please follow this documentation https://docs.metabox.io/extensions/mb-term-meta/#getting-field-value
For example:
$image = rwmb_meta( 'single_image_qn1rks1dhnn', ['object_type' => 'term', 'size' => 'thumbnail'], get_queried_object_id() ); echo '<img src='. $image['url'] .' />';Long Nguyen
ModeratorHi,
It's not a good idea to use more frontend submission forms on a page, some features might not work properly. I think you can try to pass the post ID to the URL with the parameter
?rwmb_frontend_field_post_idand redirect the user to a new page to edit the post.
Like this topic https://support.metabox.io/topic/js-call-mb_frontend_form-shortcode/Long Nguyen
ModeratorHi,
Yes, you are welcome to update the documentation. On each page, there are two buttons
Edit this page on Githubat the top and bottom of the document page that links to our Github repo. You can fork it to your Github account, and create the pull request for the changes. We will check the changes and merge them to the master branch.Long Nguyen
ModeratorHi Matt,
Meta Box does not support count post views. You can follow this article to use the code to count and show it on the frontend to use a third-party plugin
https://gretathemes.com/count-post-views/Long Nguyen
ModeratorHi,
I've tested again on my site, one is a
postfield, one is a relationship.
https://monosnap.com/file/EwEhkuZuJeYwXx3OTlbjcle7XcwOaTIt shows the name of the CPT as well.
March 8, 2022 at 11:33 PM in reply to: ✅How to Insert/Edit Relationship Field Manually? What's this Field ID? #34405Long Nguyen
ModeratorHi,
Sorry for the misunderstanding.
Because Meta Box and MB extensions are very highly customizable so when you ask "edit the relationship field manually using PHP code", I think you want to customize the select field in the relationship box as you can read here https://docs.metabox.io/extensions/mb-relationships/#syntax (name, placeholder, query args ...)
So you want to create a "connection" automatically between two posts programmatically, is that right? You can
- Follow this topic https://support.metabox.io/topic/prepopulate-relationship-field-with-current-post-id/
to useaddAPI in a callback, hook to some action likesave_post,rwmb_frontend_after_processto use the passing ID. - Delete a connection first with API
delete, then add a new connection with APIadd. - When you add more connected posts manually, you can re-order posts. This is the order parameter. Here is an example https://monosnap.com/file/OAPqvSNmOIC1T42MuLSYUKbo0nGAEf
https://developer.wordpress.org/reference/hooks/save_post/
https://docs.metabox.io/extensions/mb-frontend-submission/#form-actionsLong Nguyen
ModeratorHi Brent,
If you want to display the date time on the frontend in different formats, you can set the setting
timestampof the field totrue. Please read more on the documentation https://docs.metabox.io/fields/datetime/#template-usageLong Nguyen
ModeratorHi Brent,
You can set the attribute
sizetofullwhen using the shortcode to show full size of the image[rwmb_meta id="single_image" size="thumbnail"]Or using the code to do that, please read more on the documentation https://docs.metabox.io/fields/single-image/#template-usage
Long Nguyen
ModeratorHi Brian,
You can follow this article to add custom support to the current CPT by using the code
https://wordpress.stackexchange.com/questions/70000/how-to-add-supports-parameter-for-a-custom-post-typeLong Nguyen
ModeratorHi,
Here is an example to add the text
1234to the file name:function my_unique_filename_callback( $dir, $name, $ext ) { $name = $name . '1234'; return $name . $ext; } add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' ); function your_prefix_function_name( $meta_boxes ) { $meta_boxes[] = [ 'title' => __( 'Post Meta', 'your-text-domain' ), 'id' => 'post-meta', 'fields' => [ [ 'name' => __( 'File', 'your-text-domain' ), 'id' => 'file', 'type' => 'file', 'upload_dir' => WP_CONTENT_DIR . '/invoices/', 'unique_filename_callback' => 'my_unique_filename_callback', ], ], ]; return $meta_boxes; }Refer to this topic https://stackoverflow.com/questions/27571023/override-wp-unique-filename
Long Nguyen
ModeratorHi Cees,
Can you please share the full scenario of your case? Where do you add the function
route_functionand create the query? Some screenshots would be highly appreciated.In the View, you can use the custom query to query posts as well https://docs.metabox.io/extensions/mb-views/#custom-query
Long Nguyen
ModeratorHi,
- The custom sanitize callback also supports passing 4 parameters
$value, $field, $old_value, $object_id. You can create more conditions to check the field ID as well. - Sanitization does not support this. You can use the JS validation to prevent saving data if not passing the validation.
function linkValidation( $value, $field, $old_value, $object_id ) { if( $field['id'] == 'field-a') { $value = 'a'; } if( $field['id'] == 'field-b') { $value = 'b'; } return $value; }Read more on the documentation
https://docs.metabox.io/sanitization/#custom-sanitize-callback
https://docs.metabox.io/validation/#advanced-validation-with-jquery-validation-plugin - Follow this topic https://support.metabox.io/topic/prepopulate-relationship-field-with-current-post-id/
-
AuthorPosts