Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • gcarrenos

    (@gcarrenos)

    <?php
    
    $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
    
    if ($image) { ?>
    <div id="featuredimage" style="background-image: url('<?php echo $image; ?>')">
    </div>
    <?php } ?>

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    Try like this! I forgot to close the tag

    gcarrenos

    (@gcarrenos)

    <?php

    $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>

    if ($image) {
    <div id=”featuredimage” style=”background-image: url(‘<?php echo $image; ?>’)”>
    </div>
    <?php } ?>

    gcarrenos

    (@gcarrenos)

    This should make it work, adding this into your args
    ‘meta_key’ => ‘total_sales’,
    ‘orderby’ => ‘meta_value_num’,

    For example:

    <?php
    $args = array(
    ‘post_type’ => ‘product’,
    ‘posts_per_page’ => 4,
    ‘meta_key’ => ‘total_sales’,
    ‘orderby’ => ‘meta_value_num’,

    );

    $loop = new WP_Query( $args );
    if ( $loop->have_posts() ) {
    while ( $loop->have_posts() ) : $loop->the_post();
    woocommerce_get_template_part( ‘content’, ‘product’ );
    endwhile;
    } else {
    echo __( ‘No products found’ );
    }

    wp_reset_query();

    ?>

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