I am trying to output a table using the php array method. However, I have a user argument in my query that appears to be ignored when it's passed through WPDataTables.
This is the code:
`
<?php
// Initializing the WordPress engine in a standalone PHP file include('../../../../wp-blog-header.php');
header("HTTP/1.1 200 OK"); // Forcing the 200 OK header as WP can return 404 otherwise
// Get current user object $user = wp_get_current_user();
// Create users query arguments $u_args = array( 'meta_key' => 'nickname', //any custom field name 'meta_value' => $user->nickname, );
// Instantiate new user query and pass arguments $user_query = new WP_User_Query( $u_args );
// Create an empty array to store results from our query $users_itc_arr = array();
// Loop through query results adding user id to users array foreach ( $user_query->get_results() as $user ) { array_push($users_itc_arr, $user->ID); }
This code simply runs a user query to get user ids of all users with the same nickname (internal reasons). Then runs a WC_Order_query to get all orders from those users.
When I run the code directly through the browser by calling the php file directly, the array will return the correct results. However, when I point to the file and use the WPDT shortcode to output the table on a page, it will display all orders from all users. It's like the `'customer' => $users_itc_arr,` (line 33) parameter in WC_Order_query is being ignored by WPDT.
If yes - I'll ask you to install the Duplicator plugin. It will generate a couple of files that you can send me (along with the log-in credentials), and then I can create an exact copy of your website, see what the issue is and try to resolve it.
The Duplicator plugin can export only up to 500MB of data, so if your site is bigger than that, please use the All-in-One WP Migration plugin.
Please note that the files will be too large to attach to the ticket, so you can upload them via wetransfer.com and just send me the link.
Make sure to enable the PRIVATE response, since this is a public ticket.
I am trying to output a table using the php array method. However, I have a user argument in my query that appears to be ignored when it's passed through WPDataTables.
This is the code:
`
<?php
// Initializing the WordPress engine in a standalone PHP file
include('../../../../wp-blog-header.php');
header("HTTP/1.1 200 OK"); // Forcing the 200 OK header as WP can return 404 otherwise
// Get current user object
$user = wp_get_current_user();
// Create users query arguments
$u_args = array(
'meta_key' => 'nickname', //any custom field name
'meta_value' => $user->nickname,
);
// Instantiate new user query and pass arguments
$user_query = new WP_User_Query( $u_args );
// Create an empty array to store results from our query
$users_itc_arr = array();
// Loop through query results adding user id to users array
foreach ( $user_query->get_results() as $user ) {
array_push($users_itc_arr, $user->ID);
}
//echo '<p>ITC USERS:</p><pre>'; var_dump($users_itc_arr); echo '</pre>';
// Query orders from users array
$orders_qry = new WC_Order_Query( array(
'customer' => $users_itc_arr,
'return' => 'ids',
'posts_per_page' => -1
) );
$itc_orders = $orders_qry->get_orders();
//echo '<p>ITC ORDERS:</p><pre>'; var_dump($itc_orders); echo '</pre>';
$output = array();
foreach ( $itc_orders as $itc_order ) {
$order = wc_get_order( $itc_order );
$output[] = array(
'ID' => $order->ID,
);
}
echo serialize( $output );
?>
`
This code simply runs a user query to get user ids of all users with the same nickname (internal reasons). Then runs a WC_Order_query to get all orders from those users.
When I run the code directly through the browser by calling the php file directly, the array will return the correct results. However, when I point to the file and use the WPDT shortcode to output the table on a page, it will display all orders from all users. It's like the `'customer' => $users_itc_arr,` (line 33) parameter in WC_Order_query is being ignored by WPDT.
Hello there.
I'm not sure that it can work like this, but I forwarded the ticket to one of our developers, so as soon as I hear from him, I will let you know.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Hello again.
Can you clone your website?
If yes - I'll ask you to install the Duplicator plugin. It will generate a couple of files that you can send me (along with the log-in credentials), and then I can create an exact copy of your website, see what the issue is and try to resolve it.
The Duplicator plugin can export only up to 500MB of data, so if your site is bigger than that, please use the All-in-One WP Migration plugin.
Please note that the files will be too large to attach to the ticket, so you can upload them via wetransfer.com and just send me the link.
Make sure to enable the PRIVATE response, since this is a public ticket.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables