Home › Forums › MapPress Support › Custom mashup query on search page
- This topic has 3 replies, 2 voices, and was last updated 10 years ago by
Chris.
-
AuthorPosts
-
August 30, 2013 at 9:46 pm #13249
bazel
ParticipantHi
I have a custom db query on search page that search through post titles or post slugs. Mappress mashup is set to get the posts from that query and this is working good when posts are searched by title(like the normal search on wordpress) but the map is not showing when I search from slug. here is the loop<?php $s = get_query_var('s'); $lang = ICL_LANGUAGE_CODE; global $wpdb; $querystr = " SELECT wposts.* FROM $wpdb->posts wposts, wp_icl_translations icl_translations WHERE wposts.ID = icl_translations.element_id AND icl_translations.language_code = '".$lang."' AND wposts.post_status = 'publish' AND wposts.post_type = 'restaurant' AND (wposts.post_title LIKE '%$s%' OR wposts.post_name LIKE '%$s%') "; $pageposts = $wpdb->get_results($querystr, OBJECT); ?> <?php foreach ($pageposts as $key => $value) { $resultstr[] = $value->ID; } $result = implode(",",$resultstr); echo $result; ?> <?php echo do_shortcode('[mashup query="post__in='.$result.'&post_type=restaurant" mashupBody="address" width="95%" height="350" alignment="center" directions="none" iwType="ib"]'); ?>
August 31, 2013 at 6:01 am #13254Chris
KeymasterHi,
Try removing the do_shortcode() call and see what wp_query would fetch by itself instead – it may just be a query issue:
<?php $wpq = new WP_Query("post__in=" . $result . "&post_type=restaurant"); print_r($wpq); ?>
August 31, 2013 at 6:36 am #13255bazel
Participantits not the query, I tried like this
<?php echo do_shortcode('[mashup query="post__in=1454,1460&post_type=restaurant" mashupBody="address" width="95%" height="350" alignment="center" directions="none" iwType="ib"]'); ?>
1454 and 1460 are post id, type restaurant and this query
$args = array( 'post_type' => 'restaurant', 'post__in' => array(1454,1460) ); $wpq = new WP_Query( $args ); print_r($wpq);
prints the correct array.
The problem here is that on the search template when we search and nothing is found the map is not showing. If the search returns result then the map is here showing two POIs from the ids 1454,1460
August 31, 2013 at 8:22 am #13257Chris
KeymasterI don’t know if understand the problem – is it that you want to see an empty map when there are no matching posts for the query?
It would help you if you could email me with a login to your (test) blog along with an example, so I can see it.
-
AuthorPosts
- You must be logged in to reply to this topic.