I am trying to query posts by comparing meta value.
I have set two meta with the posts. i.e. 'start_date' and 'end_date'.
they are stored as UNIX timestamp.
Now I want to query posts on following conditions:
timestamp of current momment is after(greater than) 'start_date'.
timestamp of current momment is before(smaller than) 'end_date'.
In this case, I want both conditions to fulfill. So, I have used 'relation'=>'AND'.
So here is the print_r of the query:
Array
(
[post_type] => ads
[meta_query] => Array
(
[relation] => AND
[0] => Array
(
[kye] => start_date
[compare] => <=
[value] => 1352054503
[type] => NUMERIC
)
[1] => Array
(
[kye] => end_date
[compare] => >=
[value] => 1352054503
[type] => NUMERIC
)
)
)
Note: ads is a custom post type.
And here is meta of a post:
Array
(
[start_date] => Array
(
[0] => 1352160000
)
[end_date] => Array
(
[0] => 1352246400
)
)
I see absolutely no reason why this post should show up.
The start date timestamp(1352160000) is bigger than the current timestamp(1352054503). Which breaks condition #1.
So, why is this still showing up?
What do you think?
In your meta_query, you're using "kye" instead of "key".
Related
WC_Product_Attribute Object
(
[data:protected] => Array
(
[id] => 1
[name] => pa_color
[options] => Array
(
[0] => 26
[1] => 27
[2] => 30
)
[position] => 0
[visible] => 1
[variation] => 1
)
)
How can I access values of name, options etc
A WC_Product_Attribute object should have access to methods that will let you retrieve the protected data.
Say you have your WC_Product_Attribute stored in a variable $attribute. You should be able to use methods like $attribute->get_options() or $attribute->get_name() to get the protected data.
I would recommend reviewing the WooCommerce docs for a more comprehensive list of methods you can use:
https://woocommerce.github.io/code-reference/classes/WC-Product-Attribute.html
I want to use array_push() to add to an array, but it always adds a [0] => Array level. How can I prevent that, or take that out afterwards?
For example, I'm trying to push into the '[addOns] => Array' with this:
$addOnid='gcl1';
$addOnid_arr=array('inheritedFromId' => $addOnid);
array_push($result['addOns'], $addOnid_arr);
The array_push is resulting in this:
Array
(
[addOns] => Array
(
[inheritedFromId] => gcl2
)
[0] => Array
(
[inheritedFromId] => gcl1
)
)
And want to make it:
Array
(
[addOns] => Array
(
[inheritedFromId] => gcl2
)
(
[inheritedFromId] => gcl1
)
)
...basically just getting rid of all the [0] => Array, moving all the subarrays up a level.
Maybe I haven't been using the right queries, but I haven't been able to find out how to do this.
Simple just use this instead:
$addOnid = 'gcl1';
$addOnid_arr['addOns'][] = ['inheritedFromId' => $addOnid];
I seen other questions regarding something similar but nothing exactly like I need. I want to query the wp database for the most recent 6 posts. However, I always need it to pull one post from two certain categories.
To sum up: Pull 4 recent posts and always grab one from two specific categories totaling 6 posts. How can this be achieved? Right now I am able to pull 6 recent posts but I am not able to tell it to always pull 1 post from two other categories regardless if they are recent or not.
Array //$args
(
[post_status] => publish
[posts_per_page] => 6
[ignore_sticky_posts] => 1
[post_type] => post
[meta_key] => _thumbnail_id
[suppress_filters] =>
[] => Array
(
[0] => Array
(
[taxonomy] => category
[field] => id
[terms] => Array
(
)
)
)
)
$carousel_query = new WP_Query( $args );
if ( $carousel_query->have_posts() ) :
while ( $carousel_query->have_posts() ) : $carousel_query->the_post();
........
endwhile;
endif;
I am importing products with Variations and each variation having its own SKU. However if I include a 'sku' with a Variation, it does not add them, it adds one Variation as 'default value' and not the individual ones. If I exclude the 'sku' field then it works as expected. Yet WooCommerce documentation shows that Variants have a field of 'sku'.
This is what I am sending (With the PHP api handler):
[0] => Array
(
[sku] => BH2057A
[regular_price] => 2.99
[stock_quantity] => 29
[in_stock] => 1
[managing_stock] => 1
[attributes] => Array
(
[0] => Array
(
[name] => Alphabet
[option] => A
)
)
)
This is the variant for 'A', it goes to 'Z'. The attribute is added on the product fine. As I say this works when I do not include the sku line, but breaks when I include it.
Anyone know whats wrong?
So following the WPEngineer guide on WP_List_Table (excellent guide by the way), I managed to put together a basic table for the backend of a plugin I'm working on. Using an 'example' array, it works great. Problem I'm running into is that I can't figure out for the life of me how to replace that sample data with actual data! Adding the query where I thought it was supposed to be results in the query variable having the correct data, but the table still returns no contents. The referenced pastebin is what I have so far... any thoughts?
http://pastebin.com/f0DCacfF
CORRECTION: It IS pulling the data (if I manually add a row to the database, the table count gets updated), but it's displaying a blank table.
NOTE: It seems that the sample data is an array, whereas $wpdb->get_results is returning as a stdClass Object.
Sample data setup:
var $api_key_list = array(
array( 'id' => 1,'userid' => 'Quarter Share', 'key' => 'Nathan Lowell', 'desc' => '978-0982514542' )
);
Sample data return:
Array ( [0] => Array ( [id] => 1 [userid] => 1 [key] => 098f6bcd4621d373cade4e832627b4f6 [desc] => Test API key ) )
Query setup:
$api_key_list_query = "SELECT * from $wpapi_db_table_name";
$this->api_key_list = $wpdb->get_results($api_key_list_query);
Query return:
Array ( [0] => stdClass Object ( [id] => 1 [userid] => 1 [key] => 098f6bcd4621d373cade4e832627b4f6 [desc] => Test API key ) [1] => stdClass Object ( [id] => 2 [userid] => 1 [key] => 098f6bcd4621d373cade4e832627b4f6 [desc] => Test API key 2 ) )
Adding the following solved my problem.
$this->api_key_list = array();
$i = 0;
foreach($api_key_list_return as $obj) {
foreach($obj as $key => $val) {
$this->api_key_list[$i][$key] = $val;
}
$i++;
}