[sql]wordpress custom post_type get overriden

Dulcecita

New Member
I am having problems with my custom post type (quote) for my wordpress theme WPF. The version on github has the custom post type in functions.php, but I have moved that to a plugin (wpf quote). I also added a custom widget.The problem:My main query doesnt include the custom post type "quote" (wish is fine, this is intended). The quote post type can be reached by going to: [domain]/quote/. This works fine and on this page the widget also works fine. But it goes wrong on a none-quote page (like on the homepage). The widget show the "content" and 2 meta values. The 2 meta values are not showing on a none-quote page.I looked at the query and so I added \[code\]echo '<pre>'; print_r($GLOBALS['wp_query']->request); echo '</pre>';\[/code\] to my plugin.On a quote-page:\[code\]SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'quote' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC LIMIT 0, 5\[/code\]On a none-quote-page:\[code\]SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC LIMIT 0, 5\[/code\]The only difference is \[code\]wp_posts.post_type = 'quote'\[/code\] versus \[code\]wp_posts.post_type = 'post'\[/code\].So the first one (quote) is the right one. I dont understand why it's changing back to post on a none-quote page. This is my widget() function within my WP_Widget-child:\[code\]<?phppublic function widget($args, $instance) { extract($args, EXTR_SKIP); $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']); $read_more = $instance['read_more']; echo $before_widget; if (!empty($title)) echo $before_title . $title . $after_title;; $quotes = get_posts(array('numberposts' => 1, 'orderby' => 'rand', 'post_type' => 'quote')); if (count($quotes) > 0) { foreach($quotes as $post) { echo '<pre>'; print_r($quotes); echo '</pre>'; setup_postdata($post); // print the quote wpf_quote_print(); } if (!empty($read_more)) { printf('<p><a href="http://stackoverflow.com/questions/15869467/%s">%s</a></p>', esc_url(home_url()) . '/quote/', __('Read more quotes', 'wpf_quote')); } } else { echo '<p>' . __('There are no quotes yet', 'wpf_quote') . '</p>'; } echo $after_widget;}?>\[/code\]The function that's being called within the foreach is:\[code\]<?phpfunction wpf_quote_print() { // get the meta value's $quote_meta = get_post_custom(); // first check if 'source_is_url' and 'quote_source' are not empty and prints the source as url. Else print source within parentheses. if (!empty($quote_meta['source_is_url'][0]) and !empty($quote_meta['quote_source'][0])) { $cite = '<cite><a href="' . $quote_meta['quote_source'][0] . '">' . $quote_meta['person'][0] . '</a></cite>'; } else { $cite = '<cite>' . $quote_meta['person'][0]; if (!empty($quote_meta['quote_source'][0])) $cite .= ' (' . $quote_meta['quote_source'][0] . ')'; $cite .= '</cite>'; } // print the html echo '<blockquote>' . get_the_content() . $cite . '</blockquote>';}?>\[/code\]So why does wp change my query while I explicitly tell it to retrieve post with the type of quote? I think if I solve this then it will solve the problem I have now with not getting any meta values.If it's easier I can fork my current work on github (I am gona fork it anyways to WPF when it's fixed).
 
Top