Use $query->set multiple times with pre_get_posts?

Think of this pseudo code if sky == blue set a = 5 if grass == green set a = 7 What value will a have? Not 12. This is the exact same situation. You are setting a specific parameter to a specific value. In the second call, you are overwriting your previous value. To … Read more

Why get_header() or get_footer() does not run twice if called in the same php file?

The actual templates are loaded with require_once, so PHP automatically ignores the second attempt to load them. (You will trigger the ‘get_header’ hook twice though.) Here’s the relevant code in get_header(): $templates[] = ‘header.php’; if ( ! locate_template( $templates, true, true, $args ) ) { return false; } The third parameter to locate_header(), the second … Read more

Identify which loop you are hooking into; primary or secondary?

Just a quick update that a new method is_main_query() has been introduced in WP 3.3. Example: add_action( ‘pre_get_posts’, ‘foo_modify_query_exclude_category’ ); function foo_modify_query_exclude_category( $query ) { if ( $query->is_main_query() && ! $query->get( ‘cat’ ) ) $query->set( ‘cat’, ‘-5’ ); } Resources: WPDevel: New API in 3.3: is_main_query() Codex reference: is_main_query() Related Trac Ticket #18677

How to remove a metabox from menu editor page?

By inspecting the file /wp-admin/nav-menus.php we can see that these meta-boxes: are rendered with: <?php do_meta_boxes( ‘nav-menus’, ‘side’, null ); ?> The file /wp-admin/includes/nav-menu.php contains the corresponding add_meta_box() calls and from that we can construct the relevant removal code: function custom_remove() { remove_meta_box(‘nav-menu-theme-locations’, ‘nav-menus’, ‘side’); remove_meta_box(‘add-custom-links’, ‘nav-menus’, ‘side’); remove_meta_box(‘add-post’, ‘nav-menus’, ‘side’); remove_meta_box(‘add-page’, ‘nav-menus’, ‘side’); remove_meta_box(‘add-category’, … Read more

Hook into admin post list page

From your screenshot and explanation I guess I understand what you’re trying to accomplish. Concept Point is, that the question is more a X-Y Problem. What I’d recommend is changing the idea and use as much of what is available per default: The Quick Edit box. Quick Edit The default hook to extend quick edit … Read more

Redirect logged in users if they are on a specific page

One problem is that you’re hooking in too early. Reference the Hooks API Action Reference. Template conditionals such as is_page() are only available after the query has been set up and parsed. The earliest action that you can usually safely rely on query conditionals is pre_get_posts. You’re hooking into init, which fires much earlier: muplugins_loaded … Read more

How to show an error message after publishing a post?

I wouldn’t use that hook. Here’s why Try something like this using admin_notices. function wpsites_admin_notice() { $screen = get_current_screen(); if( ‘post’ == $screen->post_type && ‘edit’ == $screen->base ){ ?> <div class=”error”> <p><?php _e( ‘Updated Demo Message!’, ‘wpsites’ ); ?></p> </div> <?php }} add_action( ‘admin_notices’, ‘wpsites_admin_notice’ ); Untested.

How can I add an extra WooCommerce hook

You can create a hook by calling do_action, then referring to the hook in your functions.php with add_action. For example, in the theme, where you want the action to occur: do_action(‘woocommerce_before_single_product_intro’); Then in functions.php add_action(‘woocommerce_before_single_product_intro’,’your_function’,[…]); For the sake of maintainability, I’d choose a naming convention that doesn’t confuse your hooks with WooCommerce’s.

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