Filter Posts from the Main Query

Untested: function custom_home_exclude( $where=”” ) { $exclude = array(); $newsQuery = new WP_Query (array( “post_type” => “news”, “meta_key” => “post_to_blog”, “meta_value” => 1, “meta_compare” => “!=”, “posts_per_page” => “-1″, )); while ($newsQuery->have_posts()) { $newsQuery->the_post(); array_push($exclude, get_the_ID()); } wp_reset_query(); $exclude = join(‘,’, $exclude); $where .= ” AND `ID` NOT IN ($exclude)”; return $where; } function custom_home_loop($query) … Read more

Conditional hook [closed]

Where are you putting this code? Probably this code is not being executed. you should wrap everything in a function and trigger it with the wp_head hook… <?php add_action( ‘wp_head’, ‘woocommerce_conditional_hook’); function woocommerce_conditional_hook(){ function check_product_in_cart() { global $woocommerce; $box_found = false; $voucher_found = false; $other_products_found = false; //start of the loop that fetches the cart … Read more

do_action() hook into load-(page)

I have changed the do_action() for a apply_filter(). This worked as follows: // Filter save settings $settings = apply_filters( ‘gtp_theme_settings_tab_save’, $settings, $tab, $_POST ); $updated = update_option( ‘gtp_theme_settings’, $settings ); And then my add_filter in plugin file looks like: function ac_theme_settings_tab_save( $settings, $tab, $postdata ) { if( $tab == ‘adcalls’ ) { $settings[‘gtp_adcalls_domain_id’] = $postdata[‘gtp_adcalls_domain_id’]; … Read more

Plugin options, presets and filters : can you help me improve my workflow?

You hadn’t included how had you arrived at this concept, but the whole “presets” branch of logic is pretty strange. Post-filtering vs pre-filtering WordPress filters are de-facto centered on filtering results. Your my_plugin_get_options filter follows that model — the results are produced and offered for modification. Sometimes that is undesirable, what if we do all … Read more