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
- Can’t change WordPress / WooCommerce attribute value order
- WordPress archive index page
- Woocommerce custom checkout form
- Woocommerce custom field calculation
- Advanced search redirecting to another page then filter further
- Remove year from title
- The_content and Preg_replace in loaded Iframe [closed]
- How can I apply custom sanitization to new usernames?
- How do I hide an article element so only logged out users see it
- Daylight Saving Time adjustment
- Divi theme: change overlay color from default blue to back [closed]
- How to Restore Deleted Post Not in Trash
- Adding tags when creating new post
- External Link Button Under Post Excerpt on Index.php
- Hiding Short Description in Shop Page, WooCommerce
- Hide Customizer’s Widget Choices From The List
- How can I tag a menu item as visited for each unique user?
- Add table to WordPress database
- Creating php pages in wordpress and assigning them to wordpress pages
- How do I create a root link in wordpress to a PDF file?
- theme customizer – can a single option pass multiple values?