At some point, the "Featured" images that usually showed up on our homepage have stopped showing.
I've done some digging and found this template code in index.php (this is the Artificer theme by WooThemes)
This seems to be the code that handles the featured images:
<ul class="featured-products">
<!-- The first 3 -->
<?php
$args = array( 'post_type' => 'product', 'posts_per_page' => 3, 'meta_query' => array( array('key' => '_visibility','value' => array('catalog', 'visible'),'compare' => 'IN'),array('key' => '_featured','value' => 'yes')) );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); $_product;
if ( function_exists( 'get_product' ) ) {
$_product = get_product( $loop->post->ID );
} else {
$_product = new WC_Product( $loop->post->ID );
}
?><li class="featured">
<?php //woocommerce_show_product_sale_flash( $post, $_product ); ?>
<a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" />'; ?>
<h3><?php the_title(); ?> <span class="price"><?php echo $_product->get_price_html(); ?></span></h3>
</a>
</li><?php endwhile; ?><!-- the large 1 --><?php
$args = array( 'post_type' => 'product', 'posts_per_page' => 1, 'offset' => 3, 'meta_query' => array( array('key' => '_visibility','value' => array('catalog', 'visible'),'compare' => 'IN'),array('key' => '_featured','value' => 'yes')) );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
if ( function_exists( 'get_product' ) ) {
$_product = get_product( $loop->post->ID );
} else {
$_product = new WC_Product( $loop->post->ID );
}
?><li class="featured">
<?php //woocommerce_show_product_sale_flash( $post, $_product ); ?>
<a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_single'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" />'; ?>
<h3><?php the_title(); ?> <span class="price"><?php echo $_product->get_price_html(); ?></span></h3>
</a>
</li><?php endwhile; ?><!-- the last 3 --><?php
$args = array( 'post_type' => 'product', 'posts_per_page' => 3, 'offset' => 4, 'meta_query' => array( array('key' => '_visibility','value' => array('catalog', 'visible'),'compare' => 'IN'),array('key' => '_featured','value' => 'yes')) );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); $_product;
if ( function_exists( 'get_product' ) ) {
$_product = get_product( $loop->post->ID );
} else {
$_product = new WC_Product( $loop->post->ID );
}
?><li class="featured">
<?php //woocommerce_show_product_sale_flash( $post, $_product ); ?>
<a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" />'; ?>
<h3><?php the_title(); ?> <span class="price"><?php echo $_product->get_price_html(); ?></span></h3>
</a>
</li><?php endwhile; ?>
</ul>
<?php } ?>
I found out how to grab the last run SQL query, and it comes back as:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts
INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
INNER JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id )
WHERE 1=1
AND (
( wp_postmeta.meta_key = '_visibility' AND wp_postmeta.meta_value IN ('catalog','visible') )
AND ( mt1.meta_key = '_featured' AND mt1.meta_value = 'yes' ) )
AND wp_posts.post_type = 'product' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC
LIMIT 0, 3
Sure enough, if I run that in phpMyAdmin I get an ermpty result set. Why would this suddently happen? We did upgrade to WooCommerce 3.0.5 a couple of weeks back, so I'm wondering if maybe something internally has changed that needs updating?
Update: Digging into this a bit more, I found that this doesn't seem to be getting set:
( mt1.meta_key = '_featured' AND mt1.meta_value = 'yes' ) )
They are showing up as "featured" in the WooCommerce admin area though:
How does WooCommerce decide if a post is featured? My understanding from the code in question above, is that it is doing:
wp_postmeta.meta_key = "_featured"
AND
wp_postmeta.meta_value = "yes"
...but that can't be right, as literally no values in the wp_postmeta
table even match %featured%
!
UPDATE 3: As suggested, I turned on debugging in WP, and I now get this on the homepage:
Notice: Undefined index: woo_enable_lightbox in /home/costumes/web/thecostumerooms.co.uk/public_html/test/wp-content/themes/artificer/includes/theme-woocommerce.php on line 274
Notice: Undefined index: woo_shop_archives_fullwidth in /home/costumes/web/thecostumerooms.co.uk/public_html/test/wp-content/themes/artificer/includes/theme-woocommerce.php on line 91
class="home blog logged-in admin-bar no-customize-support gecko alt-style-default two-col-left ">
Notice: Undefined index: woo_display_store_info in /home/costumes/web/thecostumerooms.co.uk/public_html/test/wp-content/themes/artificer/index.php on line 141
Notice: Undefined index: woo_display_store_info in /home/costumes/web/thecostumerooms.co.uk/public_html/test/wp-content/themes/artificer/index.php on line 144
Notice: Undefined index: woo_display_store_info in /home/costumes/web/thecostumerooms.co.uk/public_html/test/wp-content/themes/artificer/index.php on line 167
That is on a vanilla install of the latest WP, along with Artificer and WooCommerce (3.0.5)
wp_postmeta
table that has meta_key => _featured, which would be why its not finding anything. Where are those values stored? I really don't know the internals of WP/WooCommerce enough to work that out (I would have assumed in the DB itself, but I can't find anything that matches "featured" in there, even though I DO have a featured product, and it shows as such on the admin panelecho "Last SQL-Query: {$loop->request}";
right after$loop = new WP_Query( $args );
, what do you get? Can you try that, and then run the SQL in phpmyadmin, and see what you get?