Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've got wp-property plugin installed, and I am trying to have a custom query, to retrieve data from the database. If I query posts from other post_type is ok, but when I try to query posts from the specific "property "post_type, generated by the plugin, it only shows me one ID or one title (see picture attached to understand... http://slatehost1.co.uk/Screen%20shot%202012-06-15%20at%2011.53.10.png ). Here is my code, I tried with normal wp-query structure, but I got the same problem:

<?php
$querystr = "
SELECT *
FROM `wp_posts`
WHERE `post_type` LIKE 'property'
ORDER BY $wpdb->posts.post_date DESC
";

$pageposts = $wpdb->get_results($querystr, OBJECT);

?>
<?php if ($pageposts): ?>
<?php global $post; ?>
<?php foreach ($pageposts as $post): ?>
<?php setup_postdata($post); ?>

<?php echo  $post->post_title ?><br />

<?php endforeach; ?>
share|improve this question

1 Answer

Try using get_posts() and the_title() instead.

<?php
global $post;
$args = array('post_type' => 'property');
$posts = get_posts($args);
foreach ($posts as $post):
    setup_postdata($post);
    the_title();
endforeach;
?>
share|improve this answer
I did already, it's now working. Same behaviour. – user17156 Jun 15 '12 at 12:56
Maybe you have something else going on in your code because I took that sample from a working page that I just developed for a client. – Joseph Jun 18 '12 at 12:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.