Plugin Author
ka2
(@ka2)
Thank you for your inquiry.
Yes, you can that both.
1) How to customize view data by getting GET param.
function my_filter_cdbt_shortcode_query_conditions( $conditions, $narrow_operator, $shortcode_name, $table ){
$filtered_tables = [ 'my_table_name' ];
$target_shortcodes = [ 'cdbt-view', 'cdbt-edit' ];
$userid_column_name = 'my_user_id_column';
if ( in_array( $shortcode_name, $target_shortcodes ) && in_array( $table, $filtered_tables ) && 'and' === $narrow_operator ) {
$_current_user_id = isset( $_GET['ID'] ) ? intval( $_GET['ID'] ) : 0;
if ( empty( $conditions ) ) {
$conditions[$userid_column_name] = $_current_user_id;
} else {
$conditions = array_merge( $conditions, [ $userid_column_name => $_current_user_id ] );
}
}
return $conditions;
}
add_filter( 'cdbt_shortcode_query_conditions', 'my_filter_cdbt_shortcode_query_conditions', 10, 4 );
Please refer too this:
https://ww.wp.xz.cn/support/topic/how-to-show-only-current-user-records-from-db/
2) How to customize entry form by getting GET param.
– For example, fills with “supplier_id” as hidden field.
function my_shortcode_custom_forms( $elements_options, $shortcode_name, $table ){
$filtered_tables = [ 'articles' ];
$target_shortcodes = [ 'cdbt-entry' ];
if ( in_array( $shortcode_name, $target_shortcodes ) && in_array( $table, $filtered_tables ) ) {
$_supplier_id = isset( $_GET['supplier_id'] ) ? intval( $_GET['supplier_id'] ) : 0;
foreach ( $elements_options as $_i => $_option ) {
if ( 'supplier_id' === $_option['elementName'] ) {
$elements_options[$_i]['elementType'] = 'hidden';
$elements_options[$_i]['defaultValue'] = $_supplier_id;
}
}
}
return $elements_options;
}
add_filter( 'cdbt_shortcode_custom_forms', 'my_shortcode_custom_forms', 10, 3 );
Thank you,
-
This reply was modified 9 years, 8 months ago by
ka2.
Hello ka2,
thank you for your swift response.
This filter function code should be added to the functions.php wordpress file, correct?
I will try it out in a few hours and let you know how it goes.
Thank you again!
Regards
-
This reply was modified 9 years, 8 months ago by
levelupfx. Reason: Added some more specific information to my question
Plugin Author
ka2
(@ka2)
Hi there,
Yes, you understand. You should insert to the functions.php in your theme.
Please try it,
Ka2,
Let’s say I want the user to insert a product with a specific supplier ID.
If I create a view shortcode to show, in some page, a table with suppliers like this:
“Please select your supplier”
ID | Supplier
_______________
1 | Toshiba
2 | Sony
Is it possible to change the table so that if the user clicks “Sony”, he is taken to the product registration page with Supplier ID = 2?
Perhaps using some of the code in my first post?
I think you show an example like this in your japanese documentation, but Google Translate only helps until a certain point π
Thank you very much!
-
This reply was modified 9 years, 8 months ago by
levelupfx.
-
This reply was modified 9 years, 8 months ago by
levelupfx.
-
This reply was modified 9 years, 8 months ago by
levelupfx.
Plugin Author
ka2
(@ka2)
Sorry for my late reply.
For example, there is below permalink to link when clicked supplier of “Sony”.
http://{your_registration_page_url}?id=2
Then, it has placed a shortcode “cdbt-entry” in your registration page.
Also, it’s as follows for filtered to render shortcode after retrieve param on url.
function my_shortcode_custom_forms( $elements_options, $shortcode_name, $table ){
$filtered_tables = [ 'your_table_name' ];
$target_shortcodes = [ 'cdbt-entry' ];
if ( in_array( $shortcode_name, $target_shortcodes ) && in_array( $table, $filtered_tables ) ) {
$_supplier_id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
foreach ( $elements_options as $_i => $_option ) {
if ( 'supplier_id' === $_option['elementName'] ) {
$elements_options[$_i]['elementType'] = 'hidden';
$elements_options[$_i]['defaultValue'] = $_supplier_id;
}
}
}
return $elements_options;
}
add_filter( 'cdbt_shortcode_custom_forms', 'my_shortcode_custom_forms', 10, 3 );
Please try it.
Thank you,