Move v2 archive results to a page

If a Search & Filter Pro v2 form showed its results as an Archive, the migration tool gives its query the Legacy v2 Archive location. While the Search & Filter Migration plugin is active, the results keep showing at the old address, eg. /products-search/ or /?sfid=123, with the old template.

This only works while the migration tool is active. Once you remove it, the old address shows your blog, a page at the same slug or a 404, and the query filters nothing.

Move the results to a normal WordPress page, then change the query’s location. The page can use the old slug, so the address stays the same, and SEO plugins recognise it as a page.

Find the Queries to Move

Search & Filter lists them under Notifications, and each one’s Location says Legacy v2 Archive, with its old address as the Results Link.

The Search & Filter Notifications panel with the Legacy v2 Archive notice and Read the guide, and a query whose Location is Legacy v2 Archive with its v2 address as the Results Link
Search & Filter lists the queries to move, and each keeps its v2 address.

The migration tool’s compatibility list shows each one’s address and template. Open it from See what to change in the notice on your Dashboard. For each query, note:

  • its ID, eg. #4
  • its address, eg. Results at /products-search/
  • its template: With the template file search.php, or With the template WordPress chooses
The compatibility list section Legacy v2 Archive results pages, with the row for Migrated: Product search: Results at /products-search/, With the template file search.php
The compatibility list shows each query’s address and template.
If the template isFollow
A file, eg. search.phpWith a Template File
The template WordPress choosesWithout a Template File

Before You Start

  • Back up your theme files.
  • Work in a child theme if the template is in a theme you didn’t build. Changes to a parent theme’s files are lost when it updates.

With a Template File

1. Turn a Copy into a Page Template

Copy the template file, eg. search.php, to a new file in your theme, eg. search-results.php, and change the copy. WordPress still uses search.php for its own search results.

At the top of the copy, add a Template Name: line. WordPress then offers it as a page template:

<?php
/**
 * Template Name: Product search results
 */

Where to put it: in the theme’s root folder, or one folder below it, eg. page-templates/. Don’t start the file name with page-: WordPress treats page-{slug}.php as the template of the page with that slug.

2. Loop Over the Search & Filter Query

The old template loops over WordPress’s main query. On a page, the main query is the page itself, so loop over a WP_Query that names the query instead. Replace 123 with the query’s ID, and keep the rest of the template, eg. get_header(), as it is.

Before:

<?php if ( have_posts() ) : ?>
	<?php while ( have_posts() ) : the_post(); ?>
		<?php get_template_part( 'content', get_post_type() ); ?>
	<?php endwhile; ?>
	<?php the_posts_pagination(); ?>
<?php else : ?>
	<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>

After:

<?php
$results_page = isset( $_GET['sf_paged'] ) ? max( 1, absint( $_GET['sf_paged'] ) ) : 1;
$results      = new WP_Query(
	array(
		'search_filter_query_id' => 123, // The query's ID.
		'paged'                  => $results_page,
	)
);
?>
<?php if ( $results->have_posts() ) : ?>
	<?php while ( $results->have_posts() ) : $results->the_post(); ?>
		<?php get_template_part( 'content', get_post_type() ); ?>
	<?php endwhile; ?>
	<?php
	echo paginate_links(
		array(
			'base'    => add_query_arg( 'sf_paged', '%#%' ),
			'format'  => '',
			'current' => $results_page,
			'total'   => $results->max_num_pages,
		)
	);
	?>
<?php else : ?>
	<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>

This keeps v2’s page links working, eg. /products-search/?sf_paged=2.

Don’t use the_posts_pagination(), next_posts_link() or previous_posts_link() here. They page WordPress’s main query, which on a page is the page itself.

3. Check Code That Depends on the Old Page Type

v2’s results page was WordPress’s posts index, and a search or archive if v2’s Force is_search or Force is_archive was ticked. On a page:

On the old results pageOn the new pageDo this
is_home(), is_search(), is_archive()is_page() is true, the others are falseChange code that checks them, eg. a search-only sidebar
get_search_query()EmptyRead the search term from $_GET['_s'] with sanitize_text_field(), and escape it when you print it
the_archive_title()Prints “Archives”Use the_title(), or write the heading in the template

Then create the page.

Without a Template File

If the list says With the template WordPress chooses, show the results with a Query Loop block on the page you create next. Search & Filter filters it, and you choose the post template for each result.

Old page links: the Query Loop block pages with its own URL argument, eg. ?query-3-page=2, so v2’s ?sf_paged=2 links open the first page.

To use your own page template instead, follow With a Template File with a copy of the template your theme uses for posts, eg. index.php.

Create the Page

  1. Go to Pages → Add New.
  2. Set its slug to match the old address, eg. products-search. If the results were at /?sfid=123, choose a slug, and update links to the old address.
  3. With a template file, choose your page template under Template. Without one, add a Query Loop block.
  4. Publish the page.
The page editor sidebar with the slug products-search and the Template Product search results
The new page uses the old slug and your page template.

Until you change the query’s location, the old address still shows the legacy results page.

Change the Query’s Location

In Search & Filter → Queries, edit the query:

  • Location: Single Post / Page / CPT, then choose your page.
  • Query: Custom with a template file, or Query Loop block with Autodetect Query on.
  • Click Update.
The query editor with Location Single Post / Page / CPT, the page Products search, Query Custom, and the Results Link still /products-search/
The query now shows its results on the page, at the same address.

The address now shows your page. If it still shows the old results, go to Settings → Permalinks and click Save Changes.

Changed your mind? While the migration tool is active, you can choose Legacy v2 Archive again. Only migrated queries offer it.

With Live Search on, set the query’s Results Container to the element that holds your results, and check its Pagination Selector.

When Every Query Is Moved

When no query has the Legacy v2 Archive location, the notice disappears, and the compatibility list no longer shows them. Once that list is empty, you can delete the migration tool. See Compatibility Mode.

Using a block theme? Follow Without a Template File, and show the results with a Query Loop block.