The Location_Items POD (‘loc_items’) uses field ‘child_loc_offers’.
The Location_Offers POD (‘loc_offers’) uses field ‘parent_loc_item’
I am using PODS to extract a complete list of Location_Items for only one Location, therefore I have set up a ‘where’ clause in the PODS parameters.
However, I want to also retrieve the related Location_Offers associated to each retrieved Location_Item.
My (latest) attempt at the ‘join’ clause is as follows:
“LEFT JOIN ‘loc_offers’ ON ‘loc_offers’.’parent_loc_item.ID’ = ‘t.ID'”
This seems to align with the example in the documentation, but it’s not working.
I found that the single example in the documentation to be somewhat vague.
What am I missing?
]]>The query is a preset CSV download of 2 tables, (it’s actually a list of artists and their exhibition venues, which may or may not be known) :
$SQL = "SELECT a.forename, a.surname, a.address_1,
a.address_2, a.address_3,
a.postcode, a.phone, a.phone2, a.email, a.website_url,
v.address_1, v.address_2, v.address_3, v.postcode,
a.wbat_artist_id, a.reg_date
FROM wbat_artist a
LEFT JOIN wbat_venue v ON ( a.venue_id = v.venue_id )
WHERE a.is_current_exhibitor = 1
ORDER BY reg_date, wbat_artist_id";
$results = $wpdb->get_results( $SQL , ARRAY_N);
$i = 16;
foreach ($results as $row)
{
for ($j=0;$j<$i;$j++)
{
$csv_output .= '"'.str_replace('"','',stripslashes($row[$j])).'",';
}
}
The $wpdb->get_results method doesn’t include columns from the second table (aliased ‘v’) even where they do exist, but issues notices of undefined indexes 12,13,14,15.
Is there something wrong with the equality operator in the JOIN part? It’s as though it never comes up true, though both columns are int(11)s and the condition is met for most of the rows. I have read in other posts of ‘limitations’ with $wpdb on custom queries but no clarification of what these limitations are.
Thanks for any help.
]]>I am using an ecommerce plugin with my WordPress installation to sell products. By default this plugin orders my product post type just like WordPress orders the default post type–newest to oldest.
In my online catalog I have products that are in stock, out of stock (which can be re-ordered), and sold (which cannot be re-ordered). I need to order these products like so: in stock > out of stock > sold. To do this, I have created a meta key called “product_stock” whose value is numeric–3 for in stock, 2 for out of stock, 1 for sold. I order them by this value using the following two functions:
// Join for ordering products and search pages by product quantity
add_filter('posts_join', 'meta_join');
function meta_join($join) {
if ( is_store_page() || is_search() ) :
global $wpdb;
//join stock
return $join . " LEFT JOIN (
SELECT *
FROM $wpdb->postmeta
WHERE meta_key = 'product_stock') AS stock
ON $wpdb->posts.ID = stock.post_id";
endif;
return $join;
}
//Orderby for ordering products and search pages by quantity
add_filter('posts_orderby', 'product_meta_orderby');
function product_meta_orderby($orderby) {
if ( is_store_page() || is_search() ) :
global $wpdb;
return " wp_posts.post_type DESC, stock.meta_value DESC, wp_posts.post_date DESC ";
endif;
return $orderby;
}
(As a side note, the is_store_page() function is one that I have created to detect whether my users are looking at one of my store pages or at a normal page or blog page.)
So basically I am wondering if there might be a faster way to implement the ordering that I need, because currently queries on my store pages run very, very slowly.
]]><center>
<br /><br />
<?php
$rand_posts = $wpdb->get_results("SELECT
FROM $wpdb->posts.*
LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_ID)
WHERE $wpdb->post.post_status = 'publish'
AND $wpdb->post.post_type = 'post'
AND $wpdb->postmeta.meta_key = 'images'
ORDER BY RAND() LIMIT 5");
foreach($rand_posts as $post){
setup_postdata($post);
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php if(function_exists('show_one_image')) {show_one_image(get_post_meta($post->ID, 'images', true)); } ?></a>
<? }
?>
<br /><br />
I’ve tried to follow the method used here:
Query based on Custom Field and Category
When the code was like this, it worked:
<center>
<br /><br />
<?php
$rand_posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'publish' AND post_type='post' ORDER BY RAND() LIMIT 5");
foreach($rand_posts as $post){
setup_postdata($post);
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php if(function_exists('show_one_image')) {show_one_image(get_post_meta($post->ID, 'images', true)); } ?></a>
<? }
?>
<br /><br />
I changed it to include a left join, as I need to show ONLY post with images in. The images is uploaded through a script, and shows up in the postmeta table, in column “Meta_Key”, and the field says image, when an image is uploaded with the post.
Right now, it doesn’t show anything at all. The site is still up, and no errormessages occurs.
It may be really obvious, and I must say, that php is not my thing – at all. So I’m hoping for a little help from someone who knows about left joins in WordPress.
Thanks in advance
]]>I’m trying to output a list of all users (with preference “visible”) for my site in a table with a few columns, but I need to draw information from both the users and usermeta table.
I am using this foreach
<?php
$order = '$wpdb->users.user_nicename';
$users = $wpdb->get_results(
"SELECT * FROM $wpdb->users
LEFT JOIN $wpdb->usermeta ON($wpdb->wp_users.ID = $wpdb->usermeta.umeta_id)
WHERE $wpdb->usermeta.account_status = 'Visible'
ORDER BY $order");
foreach($users as $user) :
?>
But nothing returns.
Can anyone help or help me perhaps make use of wp_list_authors instead.
Thanks
]]>function miniposts_join($posts) {
global $wpdb;
if (is_home()) {
$posts .= "
LEFT JOIN $wpdb->term_relationships AS relacion ON ($wpdb->posts.ID = relacion.object_id )
LEFT JOIN $wpdb->term_taxonomy AS taxonomia ON(relacion.term_taxonomy_id = taxonomia.term_taxonomy_id)
";
}
return $posts;
}
function miniposts_where($posts) {
if (is_home()) {
$posts .= " AND taxonomia.term_id <> 12
AND taxonomia.taxonomy = 'category'
";
}
return $posts;
}
but it throws duplicate posts. The duplicate posts arise whenever they are in two or more categories. Since I’m not fluent in sql I need to ask you, how can I tell the db that I only want those posts once?
]]>