Is there a full explanation on how to share a database with two WordPress sites on same server?

It is possible to add custom queries to the 2nd site, and pull posts from the first site: <?php $mydb = new wpdb(‘root’,’root’,’dev1′,’localhost’); $query_result = $mydb->get_results(“SELECT * FROM $wpdb->posts WHERE post_status=”publish””); if ($query_result) { foreach ($query_result as $result) { setup_postdata($result); get_template_part( ‘content’, get_post_format() ); } } else { echo “<p>Not found</p>” ; } ?> See … Read more

Drop Down Filter with CPT as Options for Search Form

use for search this form with custom post type list <form role=”search” method=”get” id=”searchform” action=”<?php echo home_url( “https://wordpress.stackexchange.com/” ); ?>”> <input type=”text” name=”s” id=”s” value=”Enter keywords …” onfocus=”if(this.value==this.defaultValue)this.value=””;” onblur=”if(this.value==”)this.value=this.defaultValue;”/><br /> <?php $types = get_post_types(); ?> <select name=”posttype”> <?php foreach ( $types as $type ) {?> <option name=”<?php echo $type->singular_label ; ?>” value=”<?php echo $type->singular_label ; … Read more

How to search for articles containing two words?

Ex. http://www.site.com/?s=as+sa This gives a perfect search result irrespective of the order of words. If you want to add a custom query then you can use following: $query = new WP_Query( ‘s=keyword+keyword2’ ); and iterate through your query result. Try this out.

Custom Post Type Search

Modify the searchform.php, or create one in a child theme (recommended), and you should be able to modify the form all you want. The default HTML is in /wp-includes/general-template.php, to which I have already linked, but don’t edit that. It is a Core file. Copy the markup into your searchform.php if you need a place … Read more

custom theme’s search not working

See the Codex page for Template Heirarchy – https://codex.wordpress.org/Template_Hierarchy#Search_Result_display Based on the links you provided, I’d guess the error stems from using a “static” index page. If your index.php file doesn’t contain a loop to iterate through posts, it won’t display any search results. You can retain a “static” index if you create a search.php … Read more

How To Add Class To Style Search Box

The tutorial shows you how to add a class and style it. add_filter( ‘wp_nav_menu_items’,’add_search_box’, 10, 2 ); function add_search_box( $items, $args ) { $items .= ‘<li class=”your-class”>’ . get_search_form( ‘echo=0’ ) . ‘</li>’; return $items; } For CSS questions, please ask on Stackoverflow. But the code doesn’t enable you to select between the primary or … Read more

Custom Search only for my Custom Taxonomy Page – data

You can try modifying your query using pre_get_posts filter. function mod_query() { if ($query->is_main_query() && !is_admin() && is_search()) { // test print queried search terms print_r( $query->query_vars[‘s’] ); $search_terms = $query->query_vars[‘s’]; $search_terms = preg_replace(‘/\s+/’, ‘+’, $search_terms); // test print after replacing spaces with + print_r( $query->query_vars[‘s’] ); // if all going well you can change … Read more

How do I turn this form into a search form? [closed]

Please try this , <form name=”searchBox” action=”<?php echo get_bloginfo(‘url’); ?>” class=”search-form” method=”get” role=”search” > <input type=”text” name=”s” class=”searchBox” placeholder=”search” value=”<?= $_GET[‘s’] ?>” required /> <button type=”submit” class=”searchBtn” >search</button> </form>

Search and replace titles of posts with specific tags

//Search by tags $query = new WP_Query( ‘tag=old’ ); // Then update post titles if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); //check if title have “a new” if(strpos(get_the_title(),’a new’) !== false) : $post = array( ‘ID’=> get_the_id(), ‘post_title’=> str_replace(‘a new’,’an old’,get_the_title()) ); // Update the post into the database wp_update_post( $post … Read more

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