child_of not working while searching
WP_Query does not have child_of argument. You might be looking for post_parent or post_parent__in, see Post & Page Parameters.
WP_Query does not have child_of argument. You might be looking for post_parent or post_parent__in, see Post & Page Parameters.
WP_Query will return a WP_Query object. An object will never match the string $ip that you are comparing it to. What you need to be doing is checking whether results were returned, which you can do by checking the found_posts property: $ip = $_SERVER[‘REMOTE_ADDR’]; $query = new WP_Query( array( ‘ignore_sticky_posts’ => true, ‘meta_key’ => ‘voted_IP’, … Read more
Add wp_reset_postdata(); after each loop, if you use your custom query, you should use wp_reset_query();
I heard query_posts() is bad so I shouldn’t be using that, but how else could I achieve this? Yes, query_posts is bad. You heard right. You are most of the way to doing this already. You have all the parts. You just need to mix them a little. function searchfilter($query) { if ($query->is_search()) { $query->set(‘posts_per_page’, … Read more
Try function no_attachment_page() { global $wp_query; if ( $wp_query->is_attachment() ) { $wp_query->set_404(); status_header(404); nocache_headers(); } } add_action( ‘template_redirect’, ‘no_attachment_page’, 1 ); This should result in a 404 everytime you try to access to an attachment page.
You are mixining the form display and the search logic. this is the first bad thing in your code. Second, the hook you have used are triggered everytime a query run, even the query inside your function, this bring to an infinite loop. So, first of all separate logic from display: function vkss_super_search_form( $atts=”” ) … Read more
To change the search form, filter get_search_form. You get the form as a string here, and you can change it as you need. add_filter( ‘get_search_form’, function( $form ) { // Replace the form, add additional fields return $form; }); To change the search query to the database, filter posts_search. You get the query as a … Read more
If you setting the posts to private in WordPress, you can add this to your functions.php file: function include_private_in_search( $query ) { // not an admin page and is the main query if (!is_admin() && $query->is_main_query()){ $query->set( ‘post_status’, array ( ‘publish’, ‘private’ ) ); } } add_action( ‘pre_get_posts’, ‘include_private_in_search’ ); Then you can format the … Read more
Diffrent search templates for different post types
This sounds like the perfect use case for Custom Taxonomies. And unless you plan to customize the admin backend, the Codepress Admin Columns plugin could be useful for filtering the posts using those new taxonomies. Edit (2014.01.23): Yes, you could build a “search form” where you would list the available taxonomies. The get_categories() function will … Read more