I created the following for our website, serialized php works great, except it loads a little slower as you mentioned in your example as we have 5000 records. With the php serialize method I can add an edit column, interactively, I can interact with the table result. The Mysql table is much faster to load but is there any way I can interact with it dynamically as I do below with the php example ?
<?php
// Initializing the WordPress engine in a stanalone PHP file //required include files require('wp-blog-header.php'); require_once("wp-config.php"); require_once("wp-includes/wp-db.php");
header("HTTP/1.1 200 OK"); // Forcing the 200 OK header as WP can return 404 otherwise
// Preparing a WP_query $the_query = new WP_Query( array( 'post_type' => 'product', // We only want pages 'post_count' => 50 // We do not want to limit the post count // We can define any additional arguments that we need - see Codex for the full list ) );
$return_array = array(); // Initializing the array that will be used for the table
$return_array[] = array( //'Id' => get_the_id(), // Set the ID 'Title' => get_the_title(), // Set the title 'Description'=> get_the_content(), 'Qty'=>$quantity, 'OEM'=>$oem, 'Brand'=>$brand, 'Location'=>$location, 'Image'=>$image, 'Action' =>'Edit', ); //}
}
// Now the array is prepared, we just need to serialize and output it echo serialize( $return_array );
Hi Bogdan, basically the advantage of using the php serialize method to create the table is I can dynamically generate values for the table in my php script. For example I can easily add a custom column called "Actions" to the table. (See screenshot http://codaindustriel.com/screenshot-table.png) . This custom column is used for editing the table record or linking to the table record. However the php serialize is a little slow to load for a large amount of data.
If I use the mysql query or wp_query method (which is faster according to your documentation), to create a table can I add a custom column in my php script to the table?
Sorry to disappoint you but unfortunately something like this is not possible with the plugin build in features at the moment and it require some code customization of the plugin.
If you have any link of that table created from the array can you please send me that link so we can take a look and discuss as a new feature for our future updates but for now even with if you use mysql method this will not work.
The only workaround that I can suggest is to create a mysql table and use the basic new edit features ( make that table editable).
I created the following for our website, serialized php works great, except it loads a little slower as you mentioned in your example as we have 5000 records. With the php serialize method I can add an edit column, interactively, I can interact with the table result. The Mysql table is much faster to load but is there any way I can interact with it dynamically as I do below with the php example ?
<?php
// Initializing the WordPress engine in a stanalone PHP file
//required include files
require('wp-blog-header.php');
require_once("wp-config.php");
require_once("wp-includes/wp-db.php");
header("HTTP/1.1 200 OK"); // Forcing the 200 OK header as WP can return 404 otherwise
// Preparing a WP_query
$the_query = new WP_Query(
array(
'post_type' => 'product', // We only want pages
'post_count' => 50 // We do not want to limit the post count
// We can define any additional arguments that we need - see Codex for the full list
)
);
$return_array = array(); // Initializing the array that will be used for the table
//var_dump($the_query); exit;
while( $the_query->have_posts() ){
// Fetch the post
$the_query->the_post();
$oem = get_post_meta(get_the_id(), "wccaf_oem_part_number", true);
$location = get_post_meta(get_the_id(), "wccaf_location_code", true);
$brand = get_the_terms( get_the_id(), 'product_tag' );
$brand=$brand[0]->name;
//print_r($brand[0]);exit;
//var_dump($brand); exit;
$product = wc_get_product(get_the_id());
$quantity=$product->get_stock_quantity();
if(has_post_thumbnail(get_the_id())) $image="Y"; else $image="N";
// Filling in the new array entry
//if( empty($location)){
$return_array[] = array(
//'Id' => get_the_id(), // Set the ID
'Title' => get_the_title(), // Set the title
'Description'=> get_the_content(),
'Qty'=>$quantity,
'OEM'=>$oem,
'Brand'=>$brand,
'Location'=>$location,
'Image'=>$image,
'Action' =>'Edit',
);
//}
}
// Now the array is prepared, we just need to serialize and output it
echo serialize( $return_array );
?>
HI Julian,
Thank you for your purchase.
Can you please explain me a little bit more what are you trying to achieve because I did not quite understand.
Best regards.
Kind Regards,
Miloš Jovanović
[email protected]
Rate my support
Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/
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
Hi Bogdan, basically the advantage of using the php serialize method to create the table is I can dynamically generate values for the table in my php script. For example I can easily add a custom column called "Actions" to the table. (See screenshot http://codaindustriel.com/screenshot-table.png) . This custom column is used for editing the table record or linking to the table record. However the php serialize is a little slow to load for a large amount of data.
If I use the mysql query or wp_query method (which is faster according to your documentation), to create a table can I add a custom column in my php script to the table?
HI Julian Screawn
Thank you for explanation.
Sorry to disappoint you but unfortunately something like this is not possible with the plugin build in features at the moment and it require some code customization of the plugin.
If you have any link of that table created from the array can you please send me that link so we can take a look and discuss as a new feature for our future updates but for now even with if you use mysql method this will not work.
The only workaround that I can suggest is to create a mysql table and use the basic new edit features ( make that table editable).
Best regards.
Kind Regards,
Miloš Jovanović
[email protected]
Rate my support
Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/
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