Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom filter usage #255

Open
Juma7C9 opened this issue Jun 18, 2024 · 0 comments
Open

Custom filter usage #255

Juma7C9 opened this issue Jun 18, 2024 · 0 comments

Comments

@Juma7C9
Copy link

Juma7C9 commented Jun 18, 2024

Hi,

I'm trying to understand how custom filters are supposed to be used. As I am not familiar with the plugin I'm trying to use my intuition, so please correct me if I am wrong.
Looking at 1 it seems that a comma separated list of keys should be passed to custom_filter, with the relative parameters in custom_filter_label. These two are then used to generate the $row key, which should contain all the relevant data to be passed to generate_filter_[jump|select]menu() to generate the actual filter.
What I cannot understand is why get_tp_options()2 is invoked with the filter name, as that argument should be the chosen category (i.e. teachpress_pub), if I understand correctly.

As that table contains the defined meta fields, is the custom filter supposed to work only on those or on conventional fields as well?

  • core/shortcodes.php
        ...
        $filters = explode(',', $settings['custom_filter']);
        $filter_labels = explode(',', $settings['custom_filter_label']);
        ...
        // Create the filters
        for ( $i = 0; $i < count($filters); $i++ ) {
            $row = get_tp_options($filters[$i], $order = "`variable` ASC", ARRAY_A);
            $defaults['key'] = $filters[$i];
            $defaults['title'] = $filter_labels[$i];
        ...
        $custom_filter .= self::generate_filter_selectmenu($row, $defaults);
  • core/class-db-options.php
/**
* Returns all settings of a category
* @param string $category      category name (system, course_of_studies, course_type, semester)
* @param string $order         default: setting_id DESC
* @param string $output_type   default: OBJECT
* @return object|array
* @since 4.0.0
*/
function get_tp_options($category, $order = "`setting_id` DESC", $output_type = OBJECT) {
   global $wpdb;
   $order = esc_sql($order);
   $result = $wpdb->get_results( 
       $wpdb->prepare( "SELECT * FROM " . TEACHPRESS_SETTINGS . " WHERE `category` = %s ORDER BY " . $order,  $category ), $output_type
       
   );
   return $result;
}
MariaDB [wordpress]> select * from wp_teachpress_settings;
+------------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+----------------+
| setting_id | variable              | value                                                                                                                                            | category       |
+------------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+----------------+
|          1 | db-version            | 9.0.6                                                                                                                                            | system         |
|          2 | stylesheet            | 1                                                                                                                                                | system         |
|          3 | rel_page_publications | page                                                                                                                                             | system         |
|          4 | rel_content_auto      | 0                                                                                                                                                | system         |
...                                                                                                                                     | system         |
|         10 | tp_meta_pub_meta_test | name = {tp_meta_pub_meta_test}, title = {meta_label}, type = {TEXT}, required = {false}, min = {0}, max = {0}, step = {0}, visibility = {normal} | teachpress_pub |
+------------+-----------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+----------------+

Footnotes

  1. https://github.com/winkm89/teachPress/blob/master/core/shortcodes.php#L139

  2. https://github.com/winkm89/teachPress/blob/272dba02a792887da0cf120646d324b7696f4552/core/shortcodes.php#L167

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant