You might have to check which button was clicked by user, weather it is search all post or search my post, based on that you can apply filter. Try this..
function search_author($query) {
if($query->is_search)
{
if($query->query_vars['author']=='Search My Posts')
{
$query->set('author', get_current_user_id());
}
}
return $query;
}
add_filter('pre_get_posts','search_author');
Related Posts:
- Custom search page and search by title, content and tag
- Admin search post meta
- Adding overlay search to wordpress using add action/filter
- Modify existing plugin function using filter (without modifying the plugin directly)
- Limit Media Library to Given Folder
- What is the proper way to apply the login_form_bottom filter?
- How to filter get_avatar?
- Filter results with custom field values and dropdown
- Creating search form for custom database table
- Search through custom post type and custom fields takes 5 minutes
- How-to inspect filter-able $vars?
- How to exclude certain widget from showing up on home/front page? [duplicate]
- Customise search form in the Widget
- Comment filtering (search)
- Combine multiple words in custom meta search query
- Custom Queries – Child Categories not showing up
- Customizing the default logout page of WordPress
- Is there a filter hook that I can use to change how taxonomy term names are displayed?
- Search a post using the date it was posted
- Setting custom search engine indexing for a “dynamic WordPress page” with htaccess
- Add options to the “Screen Options” section on the “Menus” editor
- Custom URL going to 404
- Search result page redirect ex.com/?s=searchterms to ex.com/searchterms
- Hi, I wanted to make custom search with multiple fields
- WordPress sort search results by custom order
- woocommerce_checkout_fields modifying existing billing_phone label created new field
- How to add an extra variable to login and authenticate it?
- Steps for custom data retrieval
- changing font size and font of a custom message added after comment
- result from custom filter admin table list backend does not work
- Custom search to display results within same page
- Search widget will search everything in the site, how to limit to only search gallery name
- How to hook up search results page to a back-end page?
- Combine two conditions in one statement syntax [closed]
- Add a searchbox to the body of a page
- Custom Search on Custom Page while preserving the main search function
- Custom Loop Query For Search Page
- Search URL parameters query [duplicate]
- Applying WP-cli Search & Replace to Static SQL Dump File
- Get users based on month ACF datepicker field
- How to create custom search page
- Dynamically Filtering Posts by Data Points – Any Pointers?
- How to append custom text to the output of ‘categories widget’?
- Custom Same Page Search
- How to Clear Empty Search values?
- Custom Register Link on Backend Form
- WP Search Form Query: Add Author’s posts into search query
- How to make WordPress search page use a relative path
- WordPress search on a custom table
- How to get the full product name by ignoring custom modification on it
- Moving Quantity after product description
- Allow WP users to sort search result on a videos site
- WP_User_Query Search Multiple Keywords from a Multi-Select Field?
- Wrap WordPress Login Form in custom Div
- Post filter with multiple checkbox taxonomy terms
- How to append the excerpt to the content in the single post page?
- Custom dropdown search form that allows users to select option B based from Option 1
- Show different pages on site depending on user choice
- Custom search results
- Custom display for homepage, tag and author pages
- WordPress custom search – pagination
- Creating a search with tag variable also added for more detailed results
- What shortcode should I use for
- Pre_Get_Posts order DESC not registering
- Apply `the_content’ filter to theme customisation live preview
- Two searchforms with different categories/posts per page
- Search a meta field for a value in all posts
- child_of not working while searching
- Custom search by several options send on form not works
- Search results load individual post in slide out div
- Custom Search Results Page
- WordPress Search on Multiple wp sites
- Create a custom search for Estate Agency WordPress site
- Add variable : 1 Week ago
- How can I make a search term redirect to a page
- Sort Search Results in Order of/by Character @ count (9) of post(s) title. (Ocean-WP theme)
- How to add filters to my site?
- Show total sales for each products on search results page Woocommerce
- Custom Search on media files PDF images pages posts
- Remove WordPress theme from a specific page
- How to keep a WordPress site synchronized between two servers?
- Why would switch_to_blog stop working?
- Modifying the Search Results
- Fatal error: Call to a member function add_rewrite_tag() on a non-object in /wp-includes/taxonomy.php on line 333
- Change login error messages? Cookie error message
- Allow non-admins to access the Customize theme page
- Query post for ‘selected category’ in archive.php
- Multiple Images/ Slider with custom post [single.php] [closed]
- How to start editing my site with WordPress?
- how to add wp-user fields to front-end form
- Show custom field value as a link
- javascript file not working in a plugin template file
- Redirect to a page while maintaining search query parameters without causing an infinite loop
- Add button to My Sites dashboard page (multisite)?
- How to define a static Home page
- Change the search results header from plugin
- Logged in only custom page
- Make Terms Under Custom Taxonomy Use Specific Single.php Template
- Problem Locating and Changing Alt Attribute Of Link
- Background image no more visible in the preview