• /***********************************************************************************/
    
    /* get_posts hack
    
    /***********************************************************************************/
    
    function pt_get_posts($args) {
    
    	global $wpdb;
    
    	$defaults = array(
    
    		'showposts' => 5, 'offset' => 0,
    
    		'cat' => '', 'orderby' => 'post_date',
    
    		'order' => 'DESC', 'include' => '',
    
    		'exclude' => '', 'meta_key' => '',
    
    		'meta_value' =>'', 'post_type' => 'post',
    
    		'post_status' => 'publish', 'post_parent' => 0
    
    	);
    
    	$r = wp_parse_args( $args, $defaults );
    
    	extract( $r, EXTR_SKIP );
    
    	$showposts = (int) $showposts;
    
    	$ecat = explode(',', $cat);
    
    	$ducky = (int) $ecat[0];
    
    	if ($ducky < 0) $exclcat = 'NOT '; else $exclcat = '';
    
    	$cat = implode(',',$ecat);
    
    	$offset = (int) $offset;
    
    	$post_parent = (int) $post_parent;
    
    	$inclusions = '';
    
    	if ( !empty($include) ) {
    
    		$offset = 0;    //ignore offset, category, exclude, meta_key, and meta_value, post_parent if using include
    
    		$cat = 0;
    
    		$exclude = '';
    
    		$meta_key = '';
    
    		$meta_value = '';
    
    		$post_parent = 0;
    
    		$incposts = preg_split('/[\s,]+/',$include);
    
    		$showposts = count($incposts);  // only the number of posts included
    
    		if ( count($incposts) ) {
    
    			foreach ( $incposts as $incpost ) {
    
    				if (empty($inclusions))
    
    					$inclusions = ' AND ( ID = ' . intval($incpost) . ' ';
    
    				else
    
    					$inclusions .= ' OR ID = ' . intval($incpost) . ' ';
    
    			}
    
    		}
    
    	}
    
    	if (!empty($inclusions))
    
    		$inclusions .= ')';
    
    	$exclusions = '';
    
    	if ( !empty($exclude) ) {
    
    		$exposts = preg_split('/[\s,]+/',$exclude);
    
    		if ( count($exposts) ) {
    
    			foreach ( $exposts as $expost ) {
    
    				if (empty($exclusions))
    
    					$exclusions = ' AND ( ID <> ' . intval($expost) . ' ';
    
    				else
    
    					$exclusions .= ' AND ID <> ' . intval($expost) . ' ';
    
    			}
    
    		}
    
    	}
    
    	if (!empty($exclusions))
    
    		$exclusions .= ')';
    
    	$query  = "SELECT DISTINCT * FROM $wpdb->posts ";
    
    	$query .= empty( $cat ) ? '' : ", $wpdb->term_relationships, $wpdb->term_taxonomy  ";
    
    	$query .= empty( $meta_key ) ? '' : ", $wpdb->postmeta ";
    
    	$query .= " WHERE 1=1 ";
    
    	$query .= empty( $post_type ) ? '' : "AND post_type = '$post_type' ";
    
    	$query .= empty( $post_status ) ? '' : "AND post_status = '$post_status' ";
    
    	$query .= "$exclusions $inclusions " ;
    
    	$query .= empty( $cat ) ? '' : "AND ($wpdb->posts.ID = $wpdb->term_relationships.object_id AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id AND $wpdb->term_taxonomy.term_id ".$exclcat."IN (" . $cat. ") AND $wpdb->term_taxonomy.taxonomy = 'category') ";
    
    	$query .= empty( $post_parent ) ? '' : "AND $wpdb->posts.post_parent = '$post_parent' ";
    
    	$query .= !empty( $meta_key ) && !empty($meta_value)  ? " AND ($wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '$meta_key' AND $wpdb->postmeta.meta_value = '$meta_value' )" : '';
    
    	$query .= !empty( $meta_key ) && empty($meta_value)  ? " AND ($wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key LIKE '$meta_key%' )" : '';
    
    	$query .= " GROUP BY $wpdb->posts.ID ORDER BY " . $orderby . ' ' . $order;
    
    	if ( 0 < $showposts )
    
    		$query .= " LIMIT " . $offset . ',' . $showposts;
    
    	$posts = $wpdb->get_results($query);
    
    	update_post_caches($posts);
    
    	return $posts;
    
    }
Viewing 3 replies - 16 through 18 (of 18 total)
  • https://www.ads-software.com/support/topic/347903

    I just want to do an IF STATEMENT

    //
    look for the custom field “article_thumb” ->>
    if there is no “article_thumb” then look for first image in article
    if there is no image in the article ->>
    set “default.jpg” as the article image.
    end if
    //

    https://www.ads-software.com/support/topic/347903

    This is what I did on mine see: link

    <?php $postimageurl = get_post_meta($post->ID, 'post-thumb', true);
    if ($postimageurl) {
    ?>
    <img src="<?php bloginfo('url') ?>/wp-content/themes/themename/timthumb.php?src=<?php echo $postimageurl; ?>&h=176&w=136&zc=1&q=100" alt="<?php the_title(); ?>" width="136" height="176"/>
    <?php } else { ?>
    <img src="<?php bloginfo('url') ?>/wp-content/themes/themename/timthumb.php?src=<?php bloginfo('url') ?>/wp-content/uploads/default.jpg&h=176&w=136&zc=1&q=100" alt="<?php the_title(); ?>" width="136" height="176"/></a>
    <?php } ?>

    It allows me to place a default image on if I do not specify a thumbnail. I use custom fields to place URL of my image and timthumb to generate it in different sizes

    Mark

    (@codeispoetry)

    Avoid Post Thumb Revisited; it may not be dangerous but it certainly is messy and difficult to maintain. You can now easily accomplish by using the built-in thumbnail support in WordPress 2.9. More details here:
    https://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘Is this an exploit in Post Thumb Revisited?’ is closed to new replies.