Correct way to perform non-cacheable DB query

I am not completely sure what you are talking about so I will mention the possibilities that come to mind. Maybe this… // Keep track of the last query for debug.. $this->last_query = $query; http://core.trac.wordpress.org/browser/tags/3.5.2/wp-includes/wp-db.php#L1195 … is what you are talking about. If so, your code just runs the flush method which resets $wpdb properties … Read more

Best approach to fetch data from wp options to js file or php file

Assuming you’re not using AJAX for form submission, you can use wp_localize_script(). Here’s a simplified version: In your plugin file: function wpse105919_add_scripts(){ wp_enqueue_script( ‘myjs’, plugins_url( ‘/myjs.js’, __FILE__ ) ); wp_localize_script( ‘myjs’, ‘jsLocalizedObject’, ‘hello world’); } add_action(‘wp_enqueue_scripts’, ‘wpse105919_add_scripts’); contents of myjs.js file: alert( jsLocalizedObject ); wp_localize_script() will add a global variable called jsLocalizedObject to your document’s … Read more

How to save post change url youtube link?

I think you want to change default video width. You can change default embed video width and height by embed_defaults filter. add_filter(’embed_defaults’, ‘ravs_embed_defaults’); function ravs_embed_defaults($embed_size) { if (is_single()) { // Conditionally set max height and width $embed_size[‘width’] = 640; $embed_size[‘height’] = 600; } else { // Default values $embed_size[‘width’] = 460; $embed_size[‘height’] = 600; } … Read more

Check for template part, else filter content

Two code snippets here that are pretty self explanatory: Add a template from the plugin if none is present from the theme add_filter( ‘page_template’, ‘wpse110317_append_meta’ ); function wpse110317_append_meta( $template ) { is_singular() AND ! file_exists( get_template_directory().”/{$template}” ) AND $template = plugin_dir_path( __FILE__ ).”/{$template}”; return $template; } Append something to the content until there’s a template … Read more