Support Forum » User Profile

Forum Replies Created

Viewing 15 posts - 1,186 through 1,200 (of 3,707 total)
  • Author
    Posts
  • Anh TranAnh Tran
    Keymaster

    Hi Brian,

    Thanks for the detailed reply! Ok slowly learning. For the first two snippets you provided. I’m not using a template file. I’d like to incorporate it into a shortcode in my functions.php file and then just use the shortcode to output those added values? Is that possible / what would that look like?

    Yes, of course. Here is the modified code for the 1st snippet:

    add_shortcode( 'your_shortcode', function( $atts ) {
        $output = '';
        $file = rwmb_meta( 'my_file' );
        $file = empty( $file ) ? null : reset( $file ); // Just get the first file.
        $title = rwmb_meta( 'my_file_title' );
        if ( is_array( $file ) ) {
            $output .= "<a href='{$file['url']}'>{$title}</a>";
        }
        return $output;
    } );

    But the link it generated was for the exact same page I was on. Not the pdf link? Not sure what went wrong there.

    Can you check if the current page has PDF file in the my_file field?

    Anh TranAnh Tran
    Keymaster

    Hi Sergio,

    Did you try:

    add_action( 'rwmb_field_A_after_save_field', function ( $null, $field, $new, $old, $object_id ) {
        $storage = $field['storage'];
        $storage->update( $object_id, 'field_B', 'new value' );
    }, 10, 5 );

    This code works only when the field A is put after field B in the meta box, which means field B is already saved.

    If field A is before field B, then after we run this code, field B still use value from the submission. In this case, please try this code:

    add_action( 'rwmb_field_A_after_save_field', function ( $null, $field, $new, $old, $object_id ) {
        $_POST['field_B'] = 'new value'; // Modify directly submitted value from $_POST.
    }, 10, 5 );
    in reply to: Remove HTML from textarea type field #14266
    Anh TranAnh Tran
    Keymaster

    Hi Christopher,

    The sub-fields inside groups are not run through filters. Only the filter for the top-level group is used.

    So, please use the filter of the top-level group and modify the value of the sub-fields.

    in reply to: Map field don't work in front office #14242
    Anh TranAnh Tran
    Keymaster

    Hi Sergio,

    I guess you're using another plugin that also enqueues Google Maps. The URL above is different from what Meta Box outputs. If that's correct, it's easy to explain 2 errors in the console: the API key is not provided and the limit exceeds.

    in reply to: Open Street Map: View all post of one cpt #14236
    Anh TranAnh Tran
    Keymaster

    Hi Sergo,

    The Open Street Map field is per post. If you need to display all location of all posts on a same map, you might need to write custom code. I'll make a tutorial about that later in the blog. Stay tuned.

    in reply to: Map field don't work in front office #14235
    Anh TranAnh Tran
    Keymaster

    Hi Sergo,

    Please check the browser dev console to see if there's any message from Google Maps API. Usually, Google will tell you exactly why.

    Also check the page source to see if the API key is correct. Maybe other plugins enqueue a different JS file using different a API key.

    Anh TranAnh Tran
    Keymaster

    Hi,

    I think it's a general WordPress question than specifically for Meta Box.

    These are the steps I'm thinking of (it requires some coding, though):

    in reply to: Limit the number of "favorites" in radio buttons #14233
    Anh TranAnh Tran
    Keymaster

    In the latest version of the MB Frontend Submission plugin, I added some code to disable the submit button when it's already clicked (to prevent duplicated submission). You can take it as a sample and write your own code, like this:

    function count_favorites() {...}
    
    $( 'input[type="radio"]' ).on( 'change', function() {
        var $submitButton = $( '.rwmb-form-submit' ).children( 'button' );
        if ( count_favorites() > 3 ) {
            $submitButton.prop( 'disabled', true );
        } else {
            $submitButton.prop( 'disabled', false );
        }
    } );
    Anh TranAnh Tran
    Keymaster

    Please try these solutions:

    https://wordpress.stackexchange.com/a/109804/2051
    https://wordpress.stackexchange.com/a/134916/2051 (note that in this answer, there's a check for post type of the being deleted post).

    You can also do some search on Google with the term like "wordpress delete attachments when delete post". This is how I found these answers.

    in reply to: How to refer to cloneable single_image field? #14231
    Anh TranAnh Tran
    Keymaster

    Hi,

    Yes, you can display images as a gallery. Please try this code:

    $images = rwmb_meta( 'fotos', ['size' => 'thumbnail'] );
    echo '<div class="gallery">';
    foreach ( $images as $image ) {
        echo "<a href='{$image['full_url']}'><img src='{$image['url'}'></a>";
    }
    echo '</div>';
    Anh TranAnh Tran
    Keymaster

    Hi Brian,

    Solution 1: adding a text field for file name.

    You can do that by adding a text field into your meta box, or wrap the file_advanced and text field into a group, whatever convenient for you.

    Then outputting the file using code like below (this is for the case when the file and the text field are not in a group):

    $file = rwmb_meta( 'my_file' );
    $file = empty( $file ) ? null : reset( $file ); // Just get the first file.
    $title = rwmb_meta( 'my_file_title' );
    if ( is_array( $file ) ) {
        echo "<a href='{$file['url']}'>{$title}</a>";
    }

    If they're in a group, then you can do like this:

    $group = rwmb_meta( 'my_file_group' );
    $file_ids = isset( $group['file'] ) ? $group['file'] : null;
    $file_id = empty( $file_ids ) ? null : reset( $file_id );
    $file = RWMB_File_Field::file_info( $file_id );
    $title = isset( $group['title'] ) ? $group['title'] : '';
    if ( is_array( $file ) ) {
        echo "<a href='{$file['url']}'>{$title}</a>";
    }

    Solution 2: using a page builder

    If you use a page builder, like VC or Beaver Builder, you need to fetch the data of the file to use in the plugin. Meta Box stores attachment ID, not file URL.

    A quick solution for that is writing a shortcode to get file URL from the field, like this:

    add_shortcode( 'your_file_url', function( $atts ) {
        $file = rwmb_meta( 'my_file' );
        $file = empty( $file ) ? null : reset( $file );
    
        return empty( $file ) ? '' : wp_get_attachment_url( $file );
    } );

    And use shortcode [your_file_url] in your page builder module to get the file URL.

    Anh TranAnh Tran
    Keymaster

    Hi Brian,

    Thanks a lot for your info! I've figured it out and fixed on your site. The fix is also added in the plugin.

    in reply to: Hide/Show fields on select type #14199
    Anh TranAnh Tran
    Keymaster

    Hi Dave,

    It's normal. Since when you have multiple clones, it's impossible to know which clone is affected by the value of the selected field.

    Anh TranAnh Tran
    Keymaster

    Added password_strength parameter in the latest version 1.3.0, which indicates the minimum required password strength (can be very-weak, weak, medium or strong).

    in reply to: Big security issue ... #14189
    Anh TranAnh Tran
    Keymaster

    Fixed in the version 1.3.0. I see that we don't need the user_id parameter at all, since the form is only for the current user.

Viewing 15 posts - 1,186 through 1,200 (of 3,707 total)