Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
React js - How to show search results in separate page using WordPress API

I have created search box in react where data is searchable form wordpress post api. i want to show this search results in separate page. from below code the page is redirecting to blank page

search.js

import axios from 'axios';
import React, { Component } from 'react';
import { Button } from 'react-bootstrap';
import { Redirect } from '@reach/router';

class Search extends Component {
  constructor(props) {
    super(props);
    this.state = {
      results: [],
      term: '',
    };

    this.submit = this.submit.bind(this);
    this.changeTerm = this.changeTerm.bind(this);
  }

  changeTerm(event) {
    this.setState({ term: event.target.value });
  }

  submit(event) {
    let url = 'https://example.com/wp-json/wp/v2/posts?_embed&search=' + encodeURI(this.state.term) + '&per_page=100';
    axios.get(url)
      .then(response => {
        let data = {
          results: response.data,
        };
        this.setState(data);
      })
      .catch(error => console.log(error));
  }

  render() {
    return (
      <div>
        <form onSubmit={this.submit} action="search/results">
          <input onChange={this.changeTerm} />
          <Button type="submit" bsStyle="primary">Find</Button>
        </form>
        {this.state.results.length > 0 &&
          <Redirect to={{
            pathname: '/search/results',
            state: { results: this.state.results }
          }} />
        }
      </div>
    );
  }
}

export default Search;

result.js

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!