Custom wp query for special offers

This topic contains 6 replies, has 3 voices, and was last updated by  Richard Davies 8 years ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #370307

    Richard Davies
    Buyer
    Post count: 118

    Hello,

    I am trying to write a custom query for a page, to show posts that contain latest offers only.

    The below query will bring up all the posts in the custom post type, and show the latest offers if they have them, but it also shows the posts in that custom post type even if it hasn’t got any offers.

    I only want this query to bring up the posts with special offers only.

    
    
    <?php
    
    global $post;
    
    $args = array( 
                
     'posts_per_page' => 4 , 'post_type' => 'gd_arts',);
                         
    $lastposts = get_posts( $args ); foreach ( $lastposts as $post ) : setup_postdata( $post ); ?>
    
    <h2><a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a></h2>
    
    <?php if ( has_post_thumbnail() ) { 
                the_post_thumbnail(array(486,226));
            } ?>
    <php echo $post->geodir_special_offers; ?>
    
    <?php endforeach; 
    wp_reset_postdata(); 
    ?>

    I dont think I am far off, I just need a little help to finish it off.

    any help would be appreciated

    Thanks

    #370322

    Guust
    Moderator
    Post count: 29970

    Not happy to use the shortcode?
    https://wpgeodirectory.com/docs/core-shortcodes/#poppost

    [gd_popular_post_view post_type=gd_arts layout=4 show_special_only=true]

    Thanks

    #370341

    Richard Davies
    Buyer
    Post count: 118

    Hey Guust,

    Thanks for your reply,

    here is the link to the page.

    https://www.explore-liverpool.com/latest-offers/

    It has two sections, one with my custom query (it shows the special_offers field)

    and the other is the [gd_popular_post_view post_type=gd_arts layout=4 show_special_only=true]

    The popular posts shortcode doesn’t show me the special_offers content unfortunately, until I click on the actual listing detail.

    btw this is all on a custom template in my theme.

    cheers

    #370347

    Guust
    Moderator
    Post count: 29970

    That is most likely because you have not selected to show Special Offers on the Listings page in the custom field settings. See https://wpgeodirectory.com/docs/core-place-settings/#show

    Thanks

    #370354

    Richard Davies
    Buyer
    Post count: 118

    Hey Guust, your a star! thank you.

    I got a little confused with the listings page and listings detail as they sound similar.

    Just a note, my custom query above? can this not be configured to show only posts with special offers?

    This is only because I may be able to style it a bit better.

    If not, where would I find the queries for the popular posts widgets.

    Thanks again.

    #370558

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    It could but it would need a custom query not a get_posts.
    You can install a pluign called “query monitor” to see all queries on a page.

    Thanks,

    Stiofan

    #370576

    Richard Davies
    Buyer
    Post count: 118

    Thanks Stiofan, i’ll take a look 😉

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

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount