$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>custom post types - Show listings from Impress Listing plugin in random order using taxonomy and terms|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

custom post types - Show listings from Impress Listing plugin in random order using taxonomy and terms

matteradmin10PV0评论

I am not able to get the listings to show up. I have verified the slug for the post type and the taxonomy. This code I know works because I have used it for other post types and taxonomy's. Any insight as to why this would not be working here would be appreciated. Thanks.

<?php

$tag = 'commercial_for_lease';

// Set up custom query with meta_query
$args = array (
    'post_type'              => 'wp-listings', // your property post type slug
    'posts_per_page'         => 50,
    'orderby'                => 'rand', // order by
    'order'                  => 'ASC', // Show earlier events first
    'tax_query'              => array(
                                array(
                                    'taxonomy'  => 'property-types',
                                    'field' => 'slug',
                                    'terms'     => array($tag)
                                ))
                            );

    $query = new WP_Query( $args );
        if ( $query->have_posts() ) :
        while ( $query->have_posts() ) : $query->the_post(); ?>

        <div class="col-md-4" id="<?php echo get_the_id(); ?>">
            <div class="row">
                <a href="<?php the_permalink(); ?>">
                    <div class="item-container">                                                    
                    <div class="item-container-img">
                    <?php the_post_thumbnail(); ?>
                    </div>  
                    <div class="item-container-text">
                        <h4><?php the_title(); ?><h4>
                        <h5><?php echo get_post_meta( get_the_ID(),'listing-price', true); ?></h5>                                                                   
                    </div>
                    </div>
                </a>
            </div>
   </div>

<?php endwhile; wp_reset_query(); ?>
<?php wp_reset_postdata(); 
endif;
?>

I am not able to get the listings to show up. I have verified the slug for the post type and the taxonomy. This code I know works because I have used it for other post types and taxonomy's. Any insight as to why this would not be working here would be appreciated. Thanks.

<?php

$tag = 'commercial_for_lease';

// Set up custom query with meta_query
$args = array (
    'post_type'              => 'wp-listings', // your property post type slug
    'posts_per_page'         => 50,
    'orderby'                => 'rand', // order by
    'order'                  => 'ASC', // Show earlier events first
    'tax_query'              => array(
                                array(
                                    'taxonomy'  => 'property-types',
                                    'field' => 'slug',
                                    'terms'     => array($tag)
                                ))
                            );

    $query = new WP_Query( $args );
        if ( $query->have_posts() ) :
        while ( $query->have_posts() ) : $query->the_post(); ?>

        <div class="col-md-4" id="<?php echo get_the_id(); ?>">
            <div class="row">
                <a href="<?php the_permalink(); ?>">
                    <div class="item-container">                                                    
                    <div class="item-container-img">
                    <?php the_post_thumbnail(); ?>
                    </div>  
                    <div class="item-container-text">
                        <h4><?php the_title(); ?><h4>
                        <h5><?php echo get_post_meta( get_the_ID(),'listing-price', true); ?></h5>                                                                   
                    </div>
                    </div>
                </a>
            </div>
   </div>

<?php endwhile; wp_reset_query(); ?>
<?php wp_reset_postdata(); 
endif;
?>
Share Improve this question asked Dec 7, 2018 at 22:52 StrattonStratton 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

I suggest starting your query by first only passing the post_type and posts_per_page arguments. This will let you know if you're getting the right entries and if so then begin to use your filters (orderby, order, etc).

Post a comment

comment list (0)

  1. No comments so far