Checking for existing title in custom db query not working

use get_page_by_title to get post by title. I check for it on my system $post_exist=get_page_by_title( ‘Hello world!’, ARRAY_A, ‘post’ ); if( ! empty( $post_exist ) ) { echo ‘title exist’; } else { echo ‘title not exist’; } Running successfully. In your case it may be like $title=trim($titles_arr[$i]); $post_exist=get_page_by_title( $title, ARRAY_A, ‘post’ ); if( ! … Read more

What could cause a WP Option to get truncated?

It was a 👼 character. Make sure you sanitize everything that gets written as field values, even if it’s a username. trim(preg_replace(“/[^\w\s]+/”, “”, $user->full_name)) I assumed there are no special characters in Instagram usernames. Never assume. I don’t really use Instagram, just my plugin supports it. BTW it got truncated on the first occurrence of … Read more

how to get the top 10 popular blogs

If I understand you correctly, something like this should help you. global $wpdb; $results = $wpdb->get_results( “SELECT post_author, SUM(comment_count) as comments FROM {$wpdb->posts} WHERE post_type=”post” AND post_status=”publish” GROUP BY post_author ORDER BY comments DESC LIMIT 10″); This will return you 10 authors of most commented posts (with highest sum of comments count of each post … Read more

Load stylesheet in edit category page?

The way to enqueue admin styles and scripts in targeted pages is explained here: Difference between do_action(‘admin_enqueue_scripts’, $hook_suffix) and do_action(“admin_print_styles-$hook_suffix”) syntax The Category page is the same as the Tag page, /wp-admin/edit-tags.php. So, an extra check is needed and in this case using the global variable $current_screen. add_action( ‘admin_print_styles-edit-tags.php’, function(){ global $current_screen; // Not categories, … Read more

Update plugin settings option_name for big plugin update

I think changing array keys is more of a PHP problem // Get entire array $plugin_options = get_option( ‘plugin_options’ ); $new_options = array(); if( isset( $plugin_options[‘ga_accountId’] ) ) $new_options[‘ga_account_id’] = $plugin_options[‘ga_accountId’]; // Update entire array update_option( ‘plugin_settings_general’, $new_options ); // Delte old array delete_option( ‘plugin_options’ ); Any end-user who might be using using your plugin’s … Read more