Customizing Only a Specific Menu using the “wp_nav_menu_items” Hook?

To only add the custom search box to the main menu you could pass the second parameter provided by the wp_nav_menu_items filter and check if the theme_location is the primary location add_filter(‘wp_nav_menu_items’,’search_box_function’, 10, 2); function search_box_function( $nav, $args ) { if( $args->theme_location == ‘primary’ ) return $nav.”<li class=”menu-header-search”><form action=’http://example.com/’ id=’searchform’ method=’get’><input type=”text” name=”s” id=’s’ placeholder=”Search”></form></li>”; … Read more

Extending the search context in the admin list post screen

I solved filtering the query by adding the join on the postmeta table and changing the where clause. tips on filtering the WHERE clause (often require regular expression search&replace) are here on codex: add_filter( ‘posts_join’, ‘segnalazioni_search_join’ ); function segnalazioni_search_join ( $join ) { global $pagenow, $wpdb; // I want the filter only when performing a … Read more

How to create a custom search for custom post type?

Here is what I’ve tried and got a solution with 3 steps. Let’s say your custom post type is “products“ 1 . Add Function Code here you can specify the archive-search.php function template_chooser($template) { global $wp_query; $post_type = get_query_var(‘post_type’); if( $wp_query->is_search && $post_type == ‘products’ ) { return locate_template(‘archive-search.php’); // redirect to archive-search.php } return … Read more

Finding all possible combinations of numbers to reach a given sum

This problem can be solved with a recursive combinations of all possible sums filtering out those that reach the target. Here is the algorithm in Python: This type of algorithms are very well explained in the following Stanford’s Abstract Programming lecture – this video is very recommendable to understand how recursion works to generate permutations of solutions. … Read more