I would like to create an array like this , and I'm lost with the syntax:
I can't nest the arrays together
$PeriodDayWeek = Array(
[monday] => Array
(
[start] => Array(
[from] => Morninghour,
[to] => Afternoonhour,
),
[end] => Array(
[from] => Morninghour,
[to] => Afternoonhour,
)
),
[tuesday] ...
until [sunday]
)
I have the beginning but it's not good:
$PeriodDayWeek = [];
foreach($EnglishDay as $Day):
$Day = array(
"start" => array(
"from" => $_POST['Dayweek_JoMo_FrH_'. $Day] .'h'. $_POST['Dayweek_JoMo_FrM_'. $Day] ,
"to" => $_POST['Dayweek_JoMo_ToH_'. $Day] .'h'. $_POST['Dayweek_JoMo_ToM_'. $Day]
)
);
endforeach;
$PeriodDayWeek = array_merge($Day, $EnglishDay);
$events_meta['periodevent_dayweek'] = maybe_serialize($PeriodDayWeek);
Solved :
$PeriodDayWeek =array();
foreach($EnglishDay as $day){
$PeriodDayWeek[$day] = array(
"start" => array(
"from" => $_POST['Dayweek_JoMo_FrH_'. $day] .'h'.$_POST['Dayweek_JoMo_FrM_'. $day] ,
"to" => $_POST['Dayweek_JoMo_ToH_'. $day] .'h'. $_POST['Dayweek_JoMo_ToM_'. $day]
)
);
}
$events_meta['periodevent_dayweek'] = maybe_serialize($PeriodDayWeek);
Related
I want to get product_id (from Website A ) Woocommerce APi and create a order in website B
If from Website A product_id =11 then create product_id= 1050 in website B
If product_id =121 then create product_id= 160 in website B
function create_order_from( $customer_id, $new_customer_data, $password_generated ) {
$live_ck = 'ck_blablabla';
$live_cs = 'cs_blablabla';
$live_url = 'https://www.website.com/wp-json/wc/v3/orders?consumer_key=' . $live_ck . '&consumer_secret=' . $live_cs;
$customer = new WC_Customer( $customer_id );
$body = array(
'status' => 'completed',
'meta_data' => array( array(
'key' => 'createdby',
'value' => 'website'
)),
'total' => 0,
'billing' => array(
'first_name' => $customer->get_billing_first_name(),
'email' => $customer->get_email(),
),
'line_items' => array( array(
'product_id' => 1050,
'quantity' => 1,
)),
);
$raw_response = wp_remote_post( $live_url,
array(
'headers' => array( 'Content-Type' => 'application/json' ),
'timeout' => 30,
'body' => json_encode( $body ),
)
);
}```
THank you for your help
I am on functions.php and I want to add this filter:
function graphene_alter_the_query( $request ) {
$dummy_query = new WP_Query();
$dummy_query->parse_query( $request );
if (!is_category('25')) {
$request['gdsr_sort'] = 'rating';
}
else {
$request['gdsr_sort'] = 'comment_count';
}
return $request;
}
add_filter( 'request', 'graphene_alter_the_query' );
the filter should do the same thing for all categories except cat 25 but seems like it cant tell it apart like if the IF condition is not detecting the category so I tried to debug it by looking at the values in WP_Query and I get this:
$myquery = new WP_Query(); print_r($myquery);
WP_Query Object ( [query] => Array ( [category_name] => 'my cat' ) [query_vars] => Array ( [category_name] => 'my cat' [error] => [m] => [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [name] => [pagename] => [page_id] => 0 [second] => [minute] => [hour] => [day] => 0 [monthnum] => 0 [year] => 0 [w] => 0 [tag] => [cat] => [tag_id] => [author] => [author_name] => [feed] => [tb] => [paged] => 0 [meta_key] => [meta_value] => [preview] => [s] => [sentence] => [title] => [fields] => [menu_order] => [embed] => [category__in] => Array ( ) [category__not_in] => Array ( ) [category__and] => Array ( ) [post__in] => Array ( ) [post__not_in] => Array ( ) [post_name__in] => Array ( ) [tag__in] => Array ( ) [tag__not_in] => Array ( ) [tag__and] => Array ( ) [tag_slug__in] => Array ( ) [tag_slug__and] => Array ( ) [post_parent__in] => Array ( ) [post_parent__not_in] => Array ( ) [author__in] => Array ( ) [author__not_in] => Array ( ) ) [tax_query] => WP_Tax_Query Object ( [queries] => Array ( [0] => Array ( [taxonomy] => category [terms] => Array ( [0] => 'my cat' ) [field] => slug [operator] => IN [include_children] => 1 ) ) [relation] => AND [table_aliases:protected] => Array ( ) [queried_terms] => Array ( [category] => Array ( [terms] => Array ( [0] => 'my cat' ) [field] => slug ) ) [primary_table] => [primary_id_column] => ) [meta_query] => [date_query] => [post_count] => 0 [current_post] => -1 [in_the_loop] => [comment_count] => 0 [current_comment] => -1 [found_posts] => 0 [max_num_pages] => 0 [max_num_comment_pages] => 0 [is_single] => [is_preview] => [is_page] => [is_archive] => 1 [is_date] => [is_year] => [is_month] => [is_day] => [is_time] => [is_author] => [is_category] => 1 [is_tag] => [is_tax] => [is_search] => [is_feed] => [is_comment_feed] => [is_trackback] => [is_home] => [is_privacy_policy] => [is_404] => [is_embed] => [is_paged] => [is_admin] => [is_attachment] => [is_singular] => [is_robots] => [is_favicon] => [is_posts_page] => [is_post_type_archive] => [query_vars_hash:WP_Query:private] => 6d85cdf18f3e6a58a470a3002d5807fc [query_vars_changed:WP_Query:private] => [thumbnails_cached] => [stopwords:WP_Query:private] => [compat_fields:WP_Query:private] => Array ( [0] => query_vars_hash [1] => query_vars_changed ) [compat_methods:WP_Query:private] => Array ( [0] => init_query_flags [1] =>
but both tag_id and cat appear empty. Why is that?
I have a meta_key called delivered_date, in date format, example 2021-05-13 16:01:26.
If I MUST use wc_get_orders( $args ), how can I get all orders within a date range?
Tried using the meta_compare argument but it returns nothing:
// The 2 variables below will come from a datepicker widget
$start_date = "2021-05-10 0:00:00";
$end_date = "2021-05-30 11:59:59";
$args = array(
'type' => 'shop_order',
'limit' => 100,
'paginate' => true,
'page' => 1,
'orderby' => 'id',
'order' => 'DESC',
'meta_key' => 'delivered_date',
'meta_value' => array($start_date, $end_date),
'meta_compare' => 'BETWEEN',
);
$result = wc_get_orders( $args );
You are close, use date — Format a local time/date
So you get:
// The 2 variables below will come from a datepicker widget
$start_date = date( '2021-05-10 00:00:00' );
$end_date = date( '2021-05-30 11:59:59' );
$args = array(
'orderby' => 'id',
'order' => 'DESC',
'meta_key' => 'delivered_date',
'meta_value' => array( $start_date, $end_date ),
'meta_compare' => 'BETWEEN',
);
$orders = wc_get_orders( $args );
// NOT empty
if ( ! empty ( $orders ) ) {
foreach ( $orders as $order ) {
echo '<p>ID = ' . $order->get_id() . '</p>';
}
}
Result: ID = 2525, ID = 2524, ID = 2523
I'm trying to implement a filter on wp_query to show annual archives by School Year (sept - may) rather than jan-dec. When I view a yearly archive page, such as sitename.com/2017/, I get a white screen of death, and no PHP errors.
My code in functions.php looks like the following:
add_action( 'pre_get_posts', 'school_year_filter' );
function school_year_filter($query) {
if (! is_admin() && $query->is_main_query() && $query->is_year() && $query->is_archive()) {
$year = get_query_var('year');
$year2 = $year + 1;
$query->set(
'date_query' => array(
array(
'after' => array(
'year' => "$year",
'month' => '9',
'day' => '1',
),
'before' => array(
'year' => "$year2",
'month' => '5',
'day' => '31',
),
'inclusive' => true,
),
),
);
}
}
Try this code.
I changed this line 'date_query'=>array( to 'date_query', array(.
add_action( 'pre_get_posts', 'school_year_filter' );
function school_year_filter($query) {
if (! is_admin() && $query->is_main_query() && $query->is_year() && $query->is_archive()) {
$year = get_query_var('year');
$year2 = $year + 1;
$query->set(
'date_query', array(
array(
'after' => array(
'year' => $year,
'month' => '9',
'day' => '1',
),
'before' => array(
'year' => $year2,
'month' => '5',
'day' => '31',
),
'inclusive' => true,
),
)
);
}
}
https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts#Only_Display_Search_Results_After_Specific_Date
I'm trying to make a function
that adds a shortcode which replace the shortcode into the list of attached files with pagination.
The problem is, WP_Query() doesn't return anything.
The functions's code is below.
It's in my functions.php, and It will be called in my content-page.php.
$a = shortcode_atts( array( 'number' => '10'), $atts );
//Protect against arbitrary paged values
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$args = array(
'post_type' => 'attachment',
'post_parent' => get_the_ID(),
'posts_per_page' => $a['number'],
'paged' => $paged
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
the_title();
endwhile;
$big = 999999999; // need an unlikely integer
$retuen_string .= paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $the_query->max_num_pages
) );
wp_reset_postdata();
else :
_e( 'Sorry, no posts matched your criteria.' );
endif;
And print_r($the_query) result is below.
WP_Query Object (
[query_vars] => Array (
[post_type] => attachment
[post_parent] => 26
[posts_per_page] => 15
[paged] => 1
[error] =>
[m] =>
[p] => 0
[subpost] =>
[subpost_id] =>
[attachment] =>
[attachment_id] => 0
[name] =>
[static] =>
[pagename] =>
[page_id] => 0
[second] =>
[minute] =>
[hour] =>
[day] => 0
[monthnum] => 0
[year] => 0
[w] => 0
[category_name] =>
[tag] =>
[cat] =>
[tag_id] =>
[author] =>
[author_name] =>
[feed] =>
[tb] =>
[comments_popup] =>
[meta_key] =>
[meta_value] =>
[preview] =>
[s] =>
[sentence] =>
[fields] =>
[menu_order] =>
[category__in] => Array ( )
[category__not_in] => Array ( )
[category__and] => Array ( )
[post__in] => Array ( )
[post__not_in] => Array ( )
[tag__in] => Array ( )
[tag__not_in] => Array ( )
[tag__and] => Array ( )
[tag_slug__in] => Array ( )
[tag_slug__and] => Array ( )
[post_parent__in] => Array ( )
[post_parent__not_in] => Array ( )
[author__in] => Array ( )
[author__not_in] => Array ( )
[ignore_sticky_posts] =>
[suppress_filters] =>
[cache_results] => 1
[update_post_term_cache] => 1
[update_post_meta_cache] => 1
[nopaging] =>
[comments_per_page] => 50
[no_found_rows] =>
[order] => DESC
)
[tax_query] => WP_Tax_Query Object (
[queries] => Array ( )
[relation] => AND
)
[meta_query] => WP_Meta_Query Object (
[queries] => Array ( )
[relation] =>
)
[date_query] =>
[post_count] => 0
[current_post] => -1
[in_the_loop] =>
[comment_count] => 0
[current_comment] => -1
[found_posts] => 0
[max_num_pages] => 0
[max_num_comment_pages] => 0
[is_single] => [is_preview] =>
[is_page] =>
[is_archive] =>
[is_date] =>
[is_year] =>
[is_month] =>
[is_day] =>
[is_time] =>
[is_author] =>
[is_category] =>
[is_tag] =>
[is_tax] =>
[is_search] =>
[is_feed] =>
[is_comment_feed] =>
[is_trackback] =>
[is_home] => 1
[is_404] =>
[is_comments_popup] =>
[is_paged] =>
[is_admin] =>
[is_attachment] =>
[is_singular] =>
[is_robots] =>
[is_posts_page] =>
[is_post_type_archive] =>
[query_vars_hash] => ab31e2fb8fd323e014706374fb98b349
[query_vars_changed] =>
[thumbnails_cached] =>
[stopwords:WP_Query:private] =>
[query] => Array (
[post_type] => attachment
[post_parent] => 26
[posts_per_page] => 15
[paged] => 1
)
[request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_parent = 26 AND wp_posts.post_type = 'attachment' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC LIMIT 0, 15
[posts] => Array ( )
)
Can anyone help, please?
$a = shortcode_atts( array( 'number' => '10'), $atts );
//Protect against arbitrary paged values
$temp = $the_query;
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'attachment',
'post_parent' => get_the_ID(),
'posts_per_page'=>'15',
'paged' => $paged
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
the_title();
endwhile;
$big = 999999999; // need an unlikely integer
$retuen_string .= paginate_links( array(
'base' => #add_query_arg('paged','%#%'),
'format' => '?paged=%#%',
'current' => $paged,
'total' => $the_query->max_num_pages
));
wp_reset_postdata();
$the_query = null;
$the_query = $temp;
else :
_e( 'Sorry, no posts matched your criteria.' );
endif;
I found the solution.
Had to add 'post_status' => 'inherit' in the $args.
Like this.
$args = array(
'post_type' => 'attachment',
'post_parent' => get_the_ID(),
'posts_per_page'=>'15',
'paged' => $paged,
'post_status' => 'inherit'
);
OMG. so simple.
The code was nothing wrong.
I just passed the wrong arguments...