Support

Account

Forum Replies Created

  • wow, John thanks

    I honestly did not know this existed. amazing and thank you. I will give it a try.

  • if anyone is searching for a solution to this issue, i had 2000 posts and found a way.

    just write a php script that loads wp (outside of wp theme folder).
    it should first go through groups of posts if you have to many (say grouping of 50). i did it with a url start stop var ?start=0&stop=100

    you can first load the post, take the title into a var

    then update the post using wp_update_post and the title from the var

    https://codex.wordpress.org/Function_Reference/wp_update_post

    it took about 10 mins to update all 2000 after each load and changing the start stop and because i am force saving the post, the acf default values for some fields were generated and saved.

    plus this was with wpml translated posts as well, so it was about 3800 as some translations were missing.

  • its what im afraid of.

    my only issue is that basically acf is used in combination with wpml, so that is one plugin i cannot disable and i hope this is not the problem.

    my plan of action now is to duplicate the whole site to a dev environment, scale back plugins that are non essential or not involved in anything at the core of the site admin, see what else i can remove, then hope for the best that i find the culprit and i can resolve the issue.

    The last resort is that if i ever change any ACF field value by editing the field, i always have to make sure to track if it disappears, and if it does i go into sql and reset the parent value.

    Strange thing was, it only started happening recently and i cannot for the life of me remember which plugins i updated and when.

    If you ever find the post/problem John, let me know, you would be saving me a lot of effort to check it and see if there is an immediate fix.

  • just to confirm another suspicion, its happening on every acf-field in this group.

    i have to manually edit the sql field and set its post_parent back to the acf group it should be with.

  • i take it this is a one off, meaning that you want to rip through the whole list of posts and assign the field X image to the featured image.

    Why dont you write a script (one run) that will load in all posts for assigning retroactively, check for the custom image, if it exists, set it as the thumbnail of the post.

    NOTE* whenever writing custom scripts like this, backup your database and when the script has run successfully, delete the file from your server.

    something like this, sitting in the root would probably work, this was written of the top of my head so check the code.

    <?php
    require('wp-load.php'); // get the wp api
    
    $args = array(
    'post_type' => 'your_post_type',
    'posts_per_page' => -1
    );
    
    $queryWP = new WP_Query($args);
    while ($queryWP->have_posts()) : $queryWP->the_post();
    
    // get the post id
    $postID = get_the_ID();
    // get the custom field image as an object
    $field_image = get_field("your_field_key");
    // get the image id
    $imageID = $field_image['ID'];
    // check if the post does not have a featured image and that the image id is not empty
    if(!has_post_thumbnail($postID) && $imageID!=''):
    // set the post featured image
    set_post_thumbnail( $postID , $imageID );
    // output confirmation
    echo "post set - ".$postID."<br>"
    echo "thumbnail id as featured image - ".$iamgeID."<br>";
    endif;
    
    endwhile;
    ?>
  • why dont you use a repeater in each CPT called something like ‘relational meta’ and acf update_field.

    you can use wp noonce ajax to take data from the first CPT, pass it to your function (in functions.php) with ajax check if the second CPT exists, then check if the second CPT has the data you want to save, if not, save it. This is also benifical as you can detach your logic from wp concerning post meta and use ACF as your conduit.

    an added bonus is this is all done without reloading the page.

    this would be a mix of wp, acf, js and ajax. Ping if you require further assistance.

  • oops, code wrap

    so you can simply do

    echo <img src='".$imgElement."' class='img-responsive'>";

    instead of wp_get_attachment_image_src or wp_get_attachment_image

    you dont need to get the attachment via the function call.

    check what your acf image field is set to in the group as a return value, there are options like ‘object’, ‘id’ etc, what do you have it set to. I believe you have it set to url.

    If you set it to id, i believe the previous code will work.

  • so you can simply do

    echo ““;

    instead of wp_get_attachment_image_src or wp_get_attachment_image

    you dont need to get the attachment via the function call.

    check what your acf image field is set to in the group as a return value, there are options like ‘object’, ‘id’ etc, what do you have it set to. I believe you have it set to url.

    If you set it to id, i believe the previous code will work.

  • if that fails, try changing the args array to use meta_query instead of meta_value

    $args = array (
        'post_type' => 'all_characters', // your post type
        'posts_per_page' => -1, // grab all the posts
        'meta_query' => array(
                       array('key' => 'character_image',
                             'compare' => 'EXISTS'
                       )
                       )
    );
  • can you try this so we can narrow things down.

    while ($query->have_posts()): $query->the_post();
    // because the image value is saved as attachment_id
    $imgElement =  get_field('character_image', get_the_ID());
    $imgSrc = wp_get_attachment_image_src($imgElement, 'full');
    echo "the image - ".$imgElement."<br>";
    echo "the full size image src - ".$imgSrc;
    endwhile;
  • If you have the name or url of the image, that is fine, use this function to reverse query the url to get the attachment id.

    https://frankiejarrett.com/2013/05/get-an-attachment-id-by-url-in-wordpress/

    and here was my explanation and solution

    I had the same issue on a past project where there were about 11,000 images, i knew the names of the images that came from the old system for a custom post, but i didnt know the new id when they were all in wordpress (i spent 2 hours manually uploading the images to know everything went through as i had issues with automated upload).

    And this was a gallery of images for each post, so i did the following:

    1. connected to old db and batch processed 200 posts from the old system at a time (with a start value and stop value for IDS of their old system posts), loading their custom image gallery
    2. fed them into an relational array with the SKUID of their system as a key identifier – you end up with a massive relational array of SKUID and array of images in each array slot.
    3. loaded the wordpress load.php
    4. repeat through the array to get the custom SKUID of the post
    5. load the wp post with corresponding skuid (ACF text field)
    6. foreach loop on the images in the initial array with the correct SKUID
    7. fed the image name with a prepended string for the wp-content folder
    8. gave me back the correct id so i could then insert it in to another array
    9. when ending the foreach loop i then assigned the array to the gallery field.

    this script was run on the root of the wordpress installation and removed when finished.

  • you can do this with repeater

    it works like this:

    1. create a repeater field and assign to pages, has the name of image_gallery_components
    2. repeater has : image_gallery_shortcode_name, gallery_of_images (the gallery)
    3. using flexslider to display the gallery
    4. person knows how to use shortcodes

    I have done it so that each shortcode generates an indivdual instance of flexslider using some bang-hash-rush code, change it to work for you if you want.

    The idea is to get the id from the shortcode, repeat through the rows of the repeater, and if the id in the short code is the same as the id of the repeater row, output the html for the gallery.

    simple really. And remember you can do this with vimeo and youtube embeds as well.

    in your functions.php

    /**** begin custom gallery shortcode ******/
    
    function galleryShortcode($atts) {
       extract(shortcode_atts(array(
        "id" => ''
      ), $atts));
     $wrapperString ="";
     $LiString = "";
     $rand = rand(5, 3000);
    if ( have_rows('image_gallery_components')){
     $increment = 0;
    while( have_rows('image_gallery_components') ): the_row();
    if(get_sub_field("image_gallery_shortcode_name")==$id)
    {
    
    $galleryImages = get_sub_field("gallery_of_images");
    
    foreach($galleryImages as $galleryImage)
    {
    $LiString .= "<li><img src='".$galleryImage['sizes']['large']."'></li>";
    $increment+=1;	
    }
     
    $wrapperString = "<div class='galleryWrap'>
    <div id='slides".$rand."' class='flexslider slider'>
    <ul class='slides'>".$LiString."</ul>
    </div>";
    if($increment>1)
    {
    $wrapperString.="<div id='carousel".$rand."' class='flexslider carousel'>
    <ul class='slides'>".$LiString."
    </ul>
    </div>";
    }
    $wrapperString.="</div>";
    
    }
    endwhile;
    if($increment>1)
    {
    	$append = "
    <script>
    $(document).ready(function() {
    
    // The slider being synced must be initialized first
      $('#carousel".$rand."').flexslider({
        animation: 'slide',
        controlNav: false,
        animationLoop: false,
        slideshow: false,
        itemWidth: 180,
        itemMargin: 5,
        asNavFor: '#slides".$rand."'
      });
       
      $('#slides".$rand."').flexslider({
        animation: 'slide',
        controlNav: false,
        animationLoop: false,
        slideshow: false,
    
        sync: '#carousel".$rand."'
      });
    
    });</script>";
    }
    else
    {
    $append = "
    <script>
    $(document).ready(function() {
    
    // The slider being synced must be initialized first
    
       
      $('#slides".$rand."').flexslider({
        animation: 'slide',
        controlNav: false,
        animationLoop: false,
        slideshow: false,
    
      });
    
    });</script>";	
    }
    
    }
    $wrapperString.=$append;
    return $wrapperString;
    }
    
    add_shortcode("customimagegallery", "galleryShortcode");
    /****** end custom gallery shortcodes *********/

    in your page or post (if you have assigned the location to it.

    [customimagegallery id=”my-gallery”]

    // content

    [customimagegallery id=”second-gallery”]

  • my process was

    **** backup database first, do not attempt to do it without doing so, and i take no responsibility if there is a problem and you didn’t backup.

    1. upload ACF PRO
    2. de-activate old acf plugin
    3. activate ACF PRO
    4. a box at the top appears saying to update database (it will change certain things in the database fields etc to clean up the old acf fields to match the new ACF PRO structure)
    5. check your site over to see everything is running.
    6. delete from FTP the old ACF plugin as it is no longer referenced.

Viewing 13 posts - 1 through 13 (of 13 total)