How do I count columns on a custom WPDB query?

Under straight mysql core functions you would use mysql_num_fields, but through $wpdb (wordpress database object), I found the following worked for me. $result = $wpdb->get_results(‘DESCRIBE ‘.$table,ARRAY_A); $columns = array(); foreach($result as $row) { $columns[] = $row[‘Field’]; } $num_fields = count($columns);

How can I use this code on a custom database table?

Yes you have to write a custom function and call it on your manage columns it will help you to get the necessary contents. public function xxxx_get_cpt_data($post_ID) { // $cpt_values = get_post_custom($post_ID); global $wpdb; $sql = “SELECT * FROM “. $wpdb->prefix. “custom_table WHERE post_ID=”. $post_ID. ” LIMIT 1″ ; $cpt_values = $wpdb->get_results($sql); if ($cpt_values) { … Read more

Custom columns doesn’t appear in custom post type

First, you need to declare/register the new columns: add_filter( ‘manage_tour_posts_columns’, ‘cyb_add_new_columns’ ); function cyb_add_new_columns() { $columns[‘price’] = __(‘Price column title’, ‘cyb-textdomain’ ); $columns[‘test’] = __(‘Test column title’, ‘cyb-textdomain’ ); return $columns; } Then, you can print the content of the column for each post: add_action(‘manage_tour_posts_custom_column’, ‘tour_price_col’, 10 ,2); function tour_price_col( $column, $post_id){ switch ( $column … Read more

Hide custom column in admin template screen (Elementor) [closed]

Use the second parameter $post_type passed to manage_posts_columns and ignore adding the column if it matches elementor_library: add_filter( ‘manage_posts_columns’, ‘customfield_add_column’, 5, 2 /* <= Make sure you add the 2 here to pass the second parameter to your callback */ ); function customfield_add_column( $defaults, $post_type = null ) { if ( $post_type !== ‘elementor_library’ ) … Read more

Remove custom taxonomy column from my custom post type columns

function wpse_80027_manage_columns($columns) { // remove taxonomy column unset($columns[‘taxonomy-YOUR_TAXONOMY_NAME’]); // prepend taxonomy name with ‘taxonomy-‘ // add your custom column $columns[‘CUSTOM_COLUMN_NAME’] = __(‘Column Name’); return $columns; } add_filter(‘manage_edit-sp_product_columns’, ‘wpse_80027_manage_columns’); function wpse_80027_add_img_column($name) { if(‘CUSTOM_COLUMN_NAME’ == $name) { // echo your image in ‘CUSTOM_COLUMN_NAME’ column echo ‘<img src=”https://wordpress.stackexchange.com/questions/80027/image-name.png />”; } } add_action(‘manage_sp_product_posts_custom_column’, ‘wpse_80027_add_img_column’);

How do I access the menus produced by Dashboard > Appearance > Menus

First: Use, for options(), the Settings API (tutorial). Second: Take a look at the core function and the available filters. Then take a look at the available filters: $sorted_menu_items = apply_filters( ‘wp_nav_menu_objects’, $sorted_menu_items, $args ); $items = apply_filters( ‘wp_nav_menu_items’, $items, $args ); $items = apply_filters( “wp_nav_menu_{$menu->slug}_items”, $items, $args );

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)