Forum Replies Created

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter tvermand

    (@tvermand)

    Zdravei Ivan!

    Thank you for your reply.
    Indeed, it works but not always. I found that wp_delete_attachment() can behave a strange way… Especially when using wp all import. I happens that the attachment is deleted in WP database, but not the file on the server. I cannot reproduce it all the time.
    Let’s say it’s ok.

    Thanks again for your help!
    Have a nice day,
    Tzvetan

    Thread Starter tvermand

    (@tvermand)

    Thank you very much for your quick answer! I was not so far from the truth ??

    Ok, I found.
    For those who might be interested:
    change that line:
    $qry = array('post__in' => $favorite_post_ids, 'posts_per_page'=> $post_per_page, 'orderby' => 'post__in', 'paged' => $page);
    and add your custom post type:
    $qry = array('post_type' => 'your_custom_post_type', 'post__in' => $favorite_post_ids, 'posts_per_page'=> $post_per_page, 'orderby' => 'post__in', 'paged' => $page);

    Hi, I’m having the same issue, I use custom post type and it’s not working.
    Where did you change the post_type? I cannot find that in any file.
    Thanks an lot.

    Thread Starter tvermand

    (@tvermand)

    Seem’s that it’s missing closing } related to if. Should be placed at the end.

    But my template has a lot of custom stuffs. See that shorter code that I used in content.php of twentyfourteen theme to test the plugin:

    <?php
    			$attachments = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order'));
    			if ( ! is_array($attachments) ) continue;
    			$count = count($attachments);
    			$first_attachment = array_shift($attachments);
    			?>
    			<div class="left">
    				<?php
    				$img_html = wp_get_attachment_image($first_attachment->ID , 'thumbnail');
    				$img_html = apply_filters( 'bj_lazy_load_html', $img_html );
    				echo $img_html;
    				?>
    			</div>

    Is it working for you?

    Thread Starter tvermand

    (@tvermand)

    <?php
    $args = array(
    'post_type' => 'attachment',
    'post_status' => null,
    'post_parent' => $fr_ID,
    'posts_per_page' => -1,
    'orderby' => 'menu_order',
    'order' => 'ASC'
    );
    
    $attachments = get_posts( $args );
    
    if( $attachments ) {
    
    $thumb_images = array();
    
    foreach( $attachments as $key => $attachment ) { 
    
    	$thumb_image = wp_get_attachment_image_src( $attachment -> ID, 'thumbnail' );
    
    	$thumb_images[] = $thumb_image[0];
    }
    natsort( $thumb_images );
    
    ?>
    
    <?php
    // Apply lazy load filter to images
    $img_lazy_load = '<img src="'.$thumb_images[0].'" alt="'.esc_attr( get_the_title() ).'" />';
    $img_lazy_load = apply_filters( 'bj_lazy_load_html', $img_lazy_load );
    echo $img_lazy_load;
    ?>

    I use a foreach because I have more than one image per post and need them after in my template.
    Hope it helps…

    Thread Starter tvermand

    (@tvermand)

    Thanks, you rock, works great!

    Thread Starter tvermand

    (@tvermand)

    You rock, that’s a really fast, fast answer ??

    Thanks for the clue, I was in the process of testing that just before you answered, and it works like a charm!

    Thanks again and all the best!
    Tzvétan

Viewing 8 replies - 1 through 8 (of 8 total)