Support

Account

Forum Replies Created

  • I have solved it by taking a different approach. I was trying to ‘create’ this on the back-end but realised I only need this on the front-end since everything will be managed through front-end forms.

    So I built a function to determine if the value is set and based on that an extra group is loaded (or not).

  • I tried several things like:

    remove_meta_box( 'acf-group_5adf5e5737453', 'pg_template', 'normal' );
    remove_meta_box( 'acf-group_5adf5e5737453', 'post', 'normal' );

    these are loaded, through a function which hooks into admin_init.

  • Just to be sure, you do understand, where it says {taxonomy}/{term_id} you have to replace it with ‘your variables’ ?

    echo get_field('custom_category_description', category_categoryID );

  • I had considered that (setting From/Till) as default… but there was something (which I can’t remember now) why I decided not to…

    The jQuery syntax is what I was looking for. Will test…

  • This code seems ok… should work imo.

  • It seems you have incorrect characters in your link. Fix those.

    %E2 = รข
    %80 = `
    %9D = space

  • I would use this code to retrieve the image.

    $feat_image = wp_get_attachment_image_src( get_post_thumbnail_id( $p->ID ), 'image-size', false, '' );

    This way you pass the correct post ID to retrieve the featured image from.

    Then to get the file location, you echo $feat_image[0].

  • Can you please share what you have so far ?

  • I probably completely overlooked it, but your syntax appears to be wrong.

    You use
    echo get_field('custom_category_description', 'option');
    but you need to use
    echo get_field('custom_category_description', {taxonomy}_{term_id});

    So now I’m wondering why you get an output if this is the actual code, because your code retrieves an option field value and NOT a taxonomy description (or I’m not understanding your setup fully).

  • I just realised that the default taxonomy description is also a wysiwyg editor (never realised this. I never use it).

    Have you tried that as well ?

  • Forget that last part (for now).

    I just did a test. I added a wysiwyg field to my taxonomy and added my shortcode, which is [home_url].

    When I var_dumped this field as follows:

    var_dump(get_field('content','{taxonomy}_{term_id}')); exit;

    it gives me my home_url.

    If I then echo it on my page it produces the same value.

    And I didn’t apply any filter or do something extra. This is straight out of the box. So my first guess now is you have something activated (like a filter or so) which stops this shortcode from outputting.

    Have you tested this with all plugins deactivated and on a default WP theme ?

  • Please share your code otherwise it’s a guessing game…

  • That is just the shortcode definition. Do you also have the code where you retrieve the ACF values ?

    What if you apply the filter ‘the_content’ to that output ?

  • Can you provide the code you have so far ?

  • Why not define it like this then ?

    $playlist = get_field('user_playlist', 'user_'. get_the_author_meta('ID') );

    So you won’t ‘lose’ stuff ๐Ÿ™‚

  • Ah ok…. my code gets generated after saving.

    What you want is some Javascript, which does something on.change (I think), but that is not my strong point so can’t help you there.

  • It took quite a few hours, but I fixed it myself… so if someone needs a working example, see below.

    I added an IF clause which checks if the meta field ‘_wp_attachment_context’ is set. If so, it’s the default (basic) uploader, so I can exclude this when an image is uploaded to a gallery field.

    function add_attachment( $attachment_id ) {
        $file = $this->get_location_of_attachment_file( $attachment_id );
        if ( false !== $file ) {
            if ( 'acf-upload' == get_post_meta( $attachment_id, '_wp_attachment_context', 1 ) ) {
                $path        = pathinfo( $file );
                $newfilename = $this->getToken( 10 ); // @TODO: get from setting
                $newfile = $path[ 'dirname' ] . "/" . $newfilename . "." . $path[ 'extension' ];
    
                rename( $file, $newfile );
                update_attached_file( $attachment_id, $newfile );
            }
        }
    }

    To delete the redundant images, I check for the file name before it’s renamed and use a mask to delete all files with a certain syntax.

    NOTE: If your file name has a dot in it (and not the one before the extension), then it probably won’t work. Still need a fix for it, but I’ll add an error for it…

    function after_save_post( $post_id ) {
        if ( PostTypes::PROFILE == get_post_type( $post_id ) ) {
            
            // profile pic part removed, because nothing changed
    
            $stored_gallery = get_field( 'sd_gallery', $post_id );
            if ( is_array( $stored_gallery ) ) {
                foreach ( $stored_gallery as $image ) {
                    $file             = $this->get_location_of_attachment_file( $image[ 'ID' ] );
                    $image_is_pending = get_post_meta( $image[ 'ID' ], '_image_pending', 1 );
                    if ( $file && true == $image_is_pending ) {
                        $path        = pathinfo( $file );
                        $newfilename = $this->getToken( 10 ); // @TODO: get from setting
                        $newfile     = $path[ 'dirname' ] . "/" . $newfilename . "." . $path[ 'extension' ];
    
                        rename( $file, $newfile );
                        update_attached_file( $image[ 'ID' ], $newfile );
                        if ( class_exists( 'RegenerateThumbnails_Regenerator' ) ) {
                            $regenerator = RegenerateThumbnails_Regenerator::get_instance( $image[ 'ID' ] );
                            $regenerator->regenerate();
                        }
    
                        preg_match( '~.+(/.+)~', $file, $result );
                        $file_name  = substr( $result[ 1 ], 1 );
                        $file_noext = strstr( $file_name, '.', 1 );
                        $mask       = $file_noext . '*';
                        array_map('unlink', glob(wp_upload_dir()['path'] . "/" . $mask ) );
                    }
                }
            }
        }
    }
  • This should give you a nudge in the direction.
    This code needs to placed in functions.php.

    function acf_57448( $post_id ) {
    
        $start_date = get_field( 'field_name', $post_id );
    
        // do stuff to calculate ETA
    
        update_field( 'eta_field_name', $post_id )
    
    }
    add_action( 'acf/save_post', 'acf_57448', 20 );
  • I assume that when a post is ‘downloaded’ it gets inserted in the database. Can’t you use the row ID ?

  • If I insert the code from add_attachment to after_save_post as below, then I end up with ‘double images’ because the image does gets renamed, but in a new file. It doesn’t rename the current file.

    The new files names are linked to the post, the original file names are not and thus they can not be deleted with a function, otherwise the issue would be solved.

    if ( false == $image_is_approved ) {
    
        $file = $this->get_location_of_attachment_file( $stored_profile_pic );
        if ( false !== $file ) {
            $path        = pathinfo( $file );
            $newfilename = $this->getToken( 10 );
            $newfile = $path[ 'dirname' ] . "/" . $newfilename . "." . $path[ 'extension' ];
    
            rename( $file, $newfile );
            update_attached_file( $stored_profile_pic, $newfile );
        }
    
        global $wpdb;
  • Sorry, it’s not making sense to me….

  • This would require A LOT of custom coding. This can’t be done easily.

  • Maybe a redundant question; did you register the shortcode ?

  • If you echo $playlist what does it return ?

  • So if a category is selected (in the form) then product details need to be shown, also inside the form ?

Viewing 25 posts - 51 through 75 (of 291 total)