global $post inside plugin query messes up every new post page in wp-admin

You have two problems in your code. You use $post as a iteration variable which is an habit best avoided You use setuppostdata which changes the global $post without you using any function that actually needs it your loop should look like foreach ( $pp_query as $p) : $pointer_query[] = array( ‘id’ => get_post_meta($p->ID, ‘_sbap_pointerid_text’, … Read more

Use a select box to change a php variable

To store the user defined value into the DB you can use the update_user_meta() function. And retrieve back the info with get_user_meta(). You could update the the user meta key with an AJAX call on your select change or put your select in a form and update on form submit either with $_GET or $_POST … Read more

global categories – Share specific categories in wordpress multisite

Here is a solution I found- // even before any taxonmy/terms are initialized, we reset the tables add_action( ‘init’, ‘the_dramatist_change_tax_terms_table’, 0 ); // on blog switching, we need to reset it again, so it does not use current blog’s tax/terms only // it works both on switch/restore blog add_action( ‘switch_blog’, ‘the_dramatist_change_tax_terms_table’, 0 ); function the_dramatist_change_tax_terms_table(){ … Read more

Need data from two different actions

Try $globalres=””; add_action(‘quiz_completed’, ‘mi_ld_quiz_ert’, 10, 2); function mi_ld_quiz_ert( $quizdata, $current_user ) { global $globalres; if($globalres== 0){ do_action(‘ld_update_group_access’, $current_user, 2, $remove = false )); } else{ do_action(‘ld_update_group_access’, $current_user, 14, $remove = false )); } } add_action(‘learndash_ques_single_answer_correct’, ‘my_ld_quiz_resp’,5,5); function my_ld_quiz_resp( $answerIndex, $correctAnswer, $userResponse) { global $globalres; $globalres = $answerIndex; }

using globals from wp_link_pages function

I think I figured it out. Most of WordPress is based on global variables. Even the main loop is pulling a giant global variable. So I guess it’s ok since I’m not modifying the actual values here – just pulling it out. It might not be a bad idea to throw $numpages and $page into … Read more

Creating a (global)-mapping

I figured it out myself. function generate_the_excluded_array() { global $excluded_pages; $excluded_pages = array(‘Foo’, ‘Bar’); } add_action( ‘after_setup_theme’, ‘generate_the_excluded_array’ ); And then it can be ‘imported’ using the global, as such: function example_shortcode_definition() { global $excluded_pages; echo $excluded[0]; } add_shortcode( ‘example_shortcode’, ‘example_shortcode_definition’ );

$GLOBALS[‘value1’] is not working

The correct syntax for using with global keyword. To access a global variable in WordPress, you first need to globalize the variable with global $variable; Write inside function.php as: function myfunction(){ global $get_variable; $get_value = $db->query(“SELECT * FROM mytable”)->fetch(); $get_variable = $get_value; } add_action( ‘after_theme_setup’, ‘myfunction’ ); Inside the function you can now able to … Read more

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