Support

Account

Forum Replies Created

  • Glad to say i’ve solved it myself.

    In stead of pulling post_categories, i had to pull the terms. Since its in a custom post / taxoomy, I had to pull the object_terms in stead of the post terms.

    So I’ve got my terms via $term = get_term_by('id', $dateCatId, 'gemeente'); , gemeente being my taxonomy.

    Next problem was that my wp_get_object_terms read the ID as a string and created a new category with the id as slug. Thats why i pull the ID back out on the term like this:
    wp_set_object_terms($post_id, $term->term_id, 'gemeente');

    Hope i’ve helpen someone with this, and also, if anyone has a better alternative, glad to hear it!

    function my_acf_save_post($post_id) {
    
        // bail early if no ACF data
        if (empty($_POST['acf'])) {
            return;
        }
    
        //array of category id's
        $categoryIds = array();
    
        //value of 'date' field is the cat_id
        $dateCatId = get_field('organisatie');//http://www.advancedcustomfields.com/resources/get_field/
        array_push($categoryIds, $dateCatId);
    
        $term = get_term_by('id', $dateCatId, 'gemeente');
    
        wp_set_object_terms($post_id, $term->term_id, 'gemeente');
    }
    
    // run before ACF saves the $_POST['acf'] data
    //add_action('acf/save_post', 'my_acf_save_post', 1);
    
    // run after ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'my_acf_save_post', 20);
  • Could someone help me with this? Would be very apreciated!

    M

  • Hi Nat,

    I was wondering about something on your solution.. The Lazysizes plugin uses data-srcset to lazy load the images. Since wordpress uses normal srcset, the images are not lazyloaded here. I’m using your code with lazysizes, but my network inspector shows all images are loaded at once. The images are responsive, but are not lazyloaded.

    Is there a way to fix this? would there be a way to string replace the srcset with data-srcset, or is that a bad thing?

    I am using:

        <?php
          $image = get_field('front_page_image');
          $imageID = $image['ID'];
          echo wp_get_attachment_image( $imageID, 'full', false, array( 'class' => 'lazyload image-100p', 'data-sizes' => 'auto' ) );
        ?>

    Which outputs in:
    <img width="3000" height="1931" src="http://localhost:8888/coeur_catering/wp-content/uploads/2016/05/prent2.jpg" class="image-100p lazyautosizes lazyloaded" alt="prent2" data-sizes="auto" srcset="http://localhost:8888/coeur_catering/wp-content/uploads/2016/05/prent2.jpg 3000w, http://localhost:8888/coeur_catering/wp-content/uploads/2016/05/prent2-300x193.jpg 300w, http://localhost:8888/coeur_catering/wp-content/uploads/2016/05/prent2-768x494.jpg 768w, http://localhost:8888/coeur_catering/wp-content/uploads/2016/05/prent2-1024x659.jpg 1024w, http://localhost:8888/coeur_catering/wp-content/uploads/2016/05/[email protected] 600w, http://localhost:8888/coeur_catering/wp-content/uploads/2016/05/[email protected] 1536w, http://localhost:8888/coeur_catering/wp-content/uploads/2016/05/[email protected] 2048w" sizes="440px">

    dont mind the @2x, as i’m using the wp-retina plugin.

    thanks!

  • I was able to fix this issue using this source:
    http://support.advancedcustomfields.com/forums/topic/querying-database-for-repeat-sub-fields-displaying-revisions/

    on another note: would it be possible to sort it now by meta_id? so that every added image shows up first in stead of last?

    regards!
    M

  • ok: i’ve come this far.

    I used the script for Querying the database for repeater sub field values. I deleted the meta_value part because i dont have a meta value, i only have the thumbnails (the value is the path to the thumbnail). So it should view all images used in the sub field thumbnail in the repeater gallery_repeat.

    It shows all images, but in multiple numbers.. (it shows the one repeater 3 times, the other one 5 times, …)

    this is my code: (source: http://www.advancedcustomfields.com/resources/querying-the-database-for-repeater-sub-field-values/ )

    <?php
    
    	// get all rows from the postmeta table where the sub_field (type) equals 'type_3'
    	// - http://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results
            $rows = $wpdb->get_results($wpdb->prepare( 
                "
                SELECT * 
                FROM wp_postmeta
                WHERE meta_key LIKE %s
                ",
                'gallery_repeat_%_thumbnail' // meta_name: $ParentName_$RowNumber_$ChildName
               
            ));
    
    	// loop through the results
    	if( $rows )
    	{
    		foreach( $rows as $row )
    		{
    			// for each result, find the 'repeater row number' and use it to load the image sub field!
    			preg_match('_([0-9]+)_', $row->meta_key, $matches);
    			$meta_key = 'gallery_repeat_' . $matches[0] . '_thumbnail'; // $matches[0] contains the row number!
    
    			//  use get_post_meta to load the image sub field
    			// - http://codex.wordpress.org/Function_Reference/get_post_meta
    			$image_id = get_post_meta( $row->post_id, $meta_key, true );
    
    			// load image src
    			// - http://www.advancedcustomfields.com/resources/field-types/image/
    			$src = wp_get_attachment_image_src( $image_id, 'full' );
    
    			?>
    			<div class="item">
    				<img src="<?php echo $src[0]; ?>" />
    				<p class="wp-caption-text">From 
    					<a href="<?php get_permalink( $row->post_id ); ?>">
    						<?php echo get_the_title( $row->post_id ); ?>
    					</a>
    				</p>
    			</div>
    			<?php
    
    		}
    	}
    
    	?>

    and a screenshot to show how it looks now:
    screenshot

    As you can see, it shows multiple identical images. in my thumbnails theres only one per repeater (all unique).
    It looks like it should be an easy fix, but my knowledge does not reach this far. Would help me out greatly if this was resolved!

    edit: ive noticed that everytime i edit the post, a dublicate of the image is made for some reason…

    regards,
    Mathieu

  • My mistake, seems to be conflicting with a lazyload script.

    can be closed!

  • works a charm! Thanks man!

  • Hey navid66

    this is what i got for output:

    Array ( [0] => Array ( [beelden] => Array ( [ID] => 110 [id] => 110 [alt] => [title] => (C)Carine Vangerven_DSC_1795_076 [caption] => [description] => [url] => http://localhost:8888/aod/wp-content/uploads/2014/06/CCarine-Vangerven_DSC_1795_076.jpg [width] => 2667 [height] => 4000 [sizes] => Array ( [thumbnail] => http://localhost:8888/aod/wp-content/uploads/2014/06/CCarine-Vangerven_DSC_1795_076-150x150.jpg [thumbnail-width] => 150 [thumbnail-height] => 150 [medium] => http://localhost:8888/aod/wp-content/uploads/2014/06/CCarine-Vangerven_DSC_1795_076-200x300.jpg [medium-width] => 200 [medium-height] => 300 [large] => http://localhost:8888/aod/wp-content/uploads/2014/06/CCarine-Vangerven_DSC_1795_076-682x1024.jpg [large-width] => 682 [large-height] => 1024 ) ) [caption] => ) ) Array ( [0] => Array ( [beelden] => Array ( [ID] => 65 [id] => 65 [alt] => [title] => Schermafbeelding 2014-06-29 om 13.10.11 [caption] => [description] => [url] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-29-om-13.10.11.png [width] => 773 [height] => 513 [sizes] => Array ( [thumbnail] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-29-om-13.10.11-150x150.png [thumbnail-width] => 150 [thumbnail-height] => 150 [medium] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-29-om-13.10.11-300x199.png [medium-width] => 300 [medium-height] => 199 [large] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-29-om-13.10.11.png [large-width] => 773 [large-height] => 513 ) ) [caption] => ) [1] => Array ( [beelden] => Array ( [ID] => 66 [id] => 66 [alt] => [title] => Schermafbeelding 2014-06-29 om 13.09.46 [caption] => [description] => [url] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-29-om-13.09.46.png [width] => 771 [height] => 512 [sizes] => Array ( [thumbnail] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-29-om-13.09.46-150x150.png [thumbnail-width] => 150 [thumbnail-height] => 150 [medium] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-29-om-13.09.46-300x199.png [medium-width] => 300 [medium-height] => 199 [large] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-29-om-13.09.46.png [large-width] => 771 [large-height] => 512 ) ) [caption] => ) [2] => Array ( [beelden] => Array ( [ID] => 64 [id] => 64 [alt] => [title] => Schermafbeelding 2014-06-29 om 13.10.39 [caption] => [description] => [url] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-29-om-13.10.39.png [width] => 771 [height] => 509 [sizes] => Array ( [thumbnail] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-29-om-13.10.39-150x150.png [thumbnail-width] => 150 [thumbnail-height] => 150 [medium] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-29-om-13.10.39-300x198.png [medium-width] => 300 [medium-height] => 198 [large] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-29-om-13.10.39.png [large-width] => 771 [large-height] => 509 ) ) [caption] => ) ) Array ( [0] => Array ( [beelden] => Array ( [ID] => 56 [id] => 56 [alt] => [title] => Schermafbeelding 2014-06-22 om 18.20.00 [caption] => [description] => [url] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-22-om-18.20.00.png [width] => 856 [height] => 682 [sizes] => Array ( [thumbnail] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-22-om-18.20.00-150x150.png [thumbnail-width] => 150 [thumbnail-height] => 150 [medium] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-22-om-18.20.00-300x239.png [medium-width] => 300 [medium-height] => 239 [large] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-22-om-18.20.00.png [large-width] => 856 [large-height] => 682 ) ) [caption] => ) [1] => Array ( [beelden] => Array ( [ID] => 57 [id] => 57 [alt] => [title] => Schermafbeelding 2014-06-17 om 10.36.21 [caption] => [description] => [url] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-17-om-10.36.21.png [width] => 1430 [height] => 895 [sizes] => Array ( [thumbnail] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-17-om-10.36.21-150x150.png [thumbnail-width] => 150 [thumbnail-height] => 150 [medium] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-17-om-10.36.21-300x187.png [medium-width] => 300 [medium-height] => 187 [large] => http://localhost:8888/aod/wp-content/uploads/2014/06/Schermafbeelding-2014-06-17-om-10.36.21-1024x640.png [large-width] => 1024 [large-height] => 640 ) ) [caption] => ) )
    
  • Hi navid66

    when the example u have given, if i do <img src="<?php echo $first_img ?>"> that again results in
    <img src="">

    anything i’m doing wrong?

    regards!
    Mathieu

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