You can instantly access any position in an array by specifying the index.
i.e. to get the first element of the $search_results array:
$first_result = $search_results[0];
Note if you’re not used to working with arrays, they are “0” indexed in most languages, which means the first element’s index is 0, the second is 1, etc.
This is what your loop is basically doing as well. Each time it accesses a different number directly, $search_results[$i] is just putting the value of $i in the same spot as I had the 0 above.
You can also change the value of $i in your loop if you want to start the loop over, for instance. Adding the line:
$i = 0;
…would send you back to the beginning. However I would not recommend you work with the index of a loop until you are quite comfortable with them.
Related Posts:
- Inject post (from specific category) between posts in Loop
- User Defined order on get_categories?
- Custom Loop through category menu to include sub categories
- How to exclude specific category from the get_the_category(); array
- Filter Select results based on selection
- Alert Bar section within WP loop is displaying even though there are no posts
- Display category name only once inside loop
- I’m trying to create an array with a foreach loop, but the array only stores the last item [closed]
- How do I remove a category from a wordpress loop>
- How to get the last category name of a child category?
- How to get current post category details inside “loop”?
- Problem with custom loop and wp_list_pluck [closed]
- Echoing a CSS class based on category of post in a list
- Do not duplicate posts with multiple categories in multiple loops
- Exclude category and post from loop in custom category.php
- Error trying import one category on page
- Remove the_content From Loop
- Using loop pagination on single.php
- Loop with slider (slider not loading)
- How to hide all child pages with post_query?
- How to sort posts based on the value (number) of a post’s metadata?
- Show css depending on activity type in BuddyPress activity-loop [closed]
- What is an equivalent of single_cat_title for getting the slug of the category?
- Issue adding sub category programmatically
- Why my filterable portfolio page work not perfectly between slug button and slug output WORDRPESS?
- How to exclude category ID from Looper in WordPress
- Add a specific part of current category page url to shortcode
- how do I get a specific post from a post with a subcategory in WP
- WP grandchild categories in nested ul li
- Grab posts by multiple categories
- Pass Category Name, Description and Photo into variables to pass to jQuery
- How to show single category archive
- Move category description below post list in blog
- How to pick the default selected value in wordpress dropdown?
- Iterate through posts based on array of categories
- Applying A Category to Existing Posts Where Page Title Matches Regex
- Get page that displays all children of taxonomy parent
- get author_name from queried post
- Displaying Woocommerce Product Category in WordPress
- How can I add extra word in permalink when someone click download button?
- Increase offset while looping
- selected option if current category is the value
- Blog posts repeat
- How to add condition in wordpress loop? [closed]
- Woocommerce : Can’t get product info in loop
- get_template_part based upon post’s category
- How to set variable, pass it to a partial file and remove it after?
- how to refresh div on template part?
- how to save selected option in variable for rest api category filter
- Setting default category base on theme activation
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Hide subcategories (widget)
- Counter in loop in foreach
- Let Users Choose Post Categories
- remove post that has no content
- Different post styles depending on category
- Can’t find infinite loop cause
- Checking array against author id in loop
- How do I Turn This Into An if statement?
- Load wordpress content in other domain
- How to show only subcategories in parent category not parent category?
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- Checkbox doesn’t stay checked, conten
- how to show only specific category for a template
- post thumbnail, conditions, else wont work
- Widgets in the loop if active
- List posts that don’t have a specific tag?
- Changing the_posts_navigation() html output
- Dilemma of Populating all the categories in a drop down list
- Can we count the WordPress Loop
- Display most popular posts of category
- Get post id within comments loop
- Syntax error when I try to insert my loop into an unordered list? [closed]
- WP_Query fails despite having 1 post
- Creating sub-categories via php
- Define specific category name in PHP
- Edit the_category (); for a hierarchical display
- JSON REST API WordPress only showing first 10 categories
- Category title output before opening title tag
- Add content after the first post in WP Loop
- wp_query get the 2nd post
- get taxonomy thumbnail and use it as a variable in code
- Include Parent Term in wp_list_categories
- Loop stopped working
- How to get post ID in a Page?
- Custom Pagination is Broken
- Display an image if odd number of posts in grid
- How to loop through all the attached images in a post, and get their url one by one
- How to array only one key from another array
- PHP Warning: strip_tags() expects parameter 1 to be string?
- Store post content in a php variable and output them using for loop
- How to add div blocks after certain set of post
- Echo a shortcode div after every 3 posts
- How to avoid duplicates when creating recent network posts
- Get all categories post is not in
- How to overwrite orderby with add_query_var
- Get latest post from all categories except one
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- Why in my theme I can’t see all the statics content under the posts?
- 2nd page displaying the exact same posts as my first page (minus the very first post)