Hi,
Can I send you my test page in private?
Sure, my email address is cyberhobo at cyberhobo dot net.
Hi, thanks, just sent it.
Also, would you have a clue of why nothing is returned with the query? Even adding coordinates?
Are you saying the posts appear when you loop through them, but don’t appear on a contextual map?
Yes. The same query outputs, say, a list of posts titles, or whatever is set to appear, with the query I gave you. If I insert the geo mashup code it returns a series of empty maps, one per each post that was supposed to be on the map.
Ok, the first question: why does the first query return nothing? The meta_key must be wrong. In your SQL example you’re querying by meta_value, so maybe the equivalent call to query_posts()
should be something like query_posts( 'meta_value=LI' )
.
The second question was, why are the maps in the loop empty? I think it’s because you’re using contextual map content, which looks at the WordPress query for content, but you’ve done your own query in this case, so there is nothing to be found in the WordPress global query.
Hi,
As for the first question: I just tried again with the following query inserted within the loop and outside the loop (tried both ways)
<?php query_posts( 'meta_value=LI' ); ?>
Results:<ol>
<?php while( have_posts() ) : the_post(); ?>
<li><?php the_title(); ?>
<?php echo GeoMashup::location_info('fields=lat,lng'); ?></li>
<?php endwhile; ?>
</ol>
<?php wp_reset_query(); ?>
The output was nothing as before. I do not get why, as I do query for that meta value in other parts of the site and do get results, even as of now. I use the custom query you saw above, though.
As for the second question: That makes sense. So what type of query can I use with contextual maps? Sorry if these questions may seem redundant and banal, I am quite a rookie at all this.
Thanks
I’d have to look at the SQL WordPress is generating to see what the difference is – to my mind that query_posts() call should be equivalent to your custom query. I don’t see this as a Geo Mashup issue – you’re working on getting your WordPress query right. It may require quite a bit of learning about WordPress.
Thanks. I am in for learning. If I sent you the SQL output (where do I get it??) would you point me towards some direction so I could find a way myself?
After a call to query_posts()
, look at the output of var_dump( $wp_query->last_request );
for the SQL.
Thanks. Ok this is weird. I tested it on another WP installation and the query returns results. The usual WP installation still does not return results.
I inserted the query:
<?php query_posts( 'meta_value=LI' );
var_dump( $wp_query->last_request );?>
Results:<ol>
<?php while( have_posts() ) : the_post(); ?>
<li><?php the_title(); ?>
<?php echo GeoMashup::location_info('fields=lat,lng'); ?></li>
<?php endwhile; ?>
</ol>
<?php wp_reset_query(); ?>
And with the other installation I got
NULL Results:
1. Post Title43.2549171,12.1698694
So it works right?
The usual installation (the one not working) just outputs
NULL Results:
Got no idea why it is NULL in both cases, but in one case it works. May it be a plugin creating the issue?? One is wp 2.9 (the one not working) the other one is 3.0.4 and both have the same exact plugins installed.
I made a mistake, the debug code should be var_dump( $wp_query->request );
. Hopefully that will show you the SQL, and the difference will be visible.
Yes that output the SQL, and I can spot some random query that is really uncalled for!!
This is the working one
string(302) " SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')AND wp_postmeta.meta_value = 'LI' ORDER BY post_date DESC LIMIT 0, 10"
And this is the not working one
string(380) " SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) LEFT JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish')AND wp_postmeta.meta_value = 'LI' AND wp_postmeta.meta_key = 'budget' ORDER BY (wp_postmeta.meta_value+0) DESC LIMIT 0, 10"
You can tell there are some weird calls to meta key “budget”, which is one of the keys, but certainly not called in the query. I have no idea why this is the case. Could any other custom query in the template be injecting those in the custom query? Thanks for the SQL query by the way! It is a great tool for debugging!
I’d suspect that code in a plugin or possibly the theme is injecting the unwanted code. Sometimes the suppress_filters parameter will prevent it:
query_posts( 'meta_value=LI&suppress_filters=1' );
In any case, I think we’ve eliminated Geo Mashup as the cause, no?
Yes, that is right, Geo Mashup is not the cause, that was clear from the moment I had one installation working and the other not working. I was just asking a little extra help from you to head towards the right direction, and you did help. Thanks a lot!
PS: suppress_filters did the trick!! Thanks a lot again!
Also for others that maybe encounter similar issues:
I found out that using arrays also works great and I can select only posts that belong to a certain number of categories and return only those that satisfy all the categories queried. I do not need to suppress filters with the array.
An example is:
query_posts(array('category__and'=>array(2,6),'showposts'=>2,'orderby'=>title,'order'=>DESC));
It will take any parameter as if it was outside the array using the above syntax.