Use wpsolr_search in php script outside the wordpress theme

  • matteo.cattelan
    Participant
    10 months, 3 weeks ago #34368

    Hi,
    I’m setting up a wp site with wpsolr pro version for a customer,
    i have to create a php script for generate a sitemap with wpsolr pro but i can’t include the classes.
    This is my code:

    require_once('/data/wp/wp-load.php');
    require_once('/data/wp/wp-content/plugins/wpsolr-pro/wpsolr-pro.php');
    
    // Set maximum URLs per file
    $max_urls = 50000;
    
    // Get all published pages
    $args = array(
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => -1
    );
    $query = new wpsolr_search($args);
    
    // Create sitemap files
    $file_count = 0;
    $url_count = 0;
    $sitemap_content = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
    $sitemap_content .= '<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
    foreach ($results['posts'] as $post)  {
      $query-> $post;
      $url = get_permalink( $post->ID );
      $modified = $post->post_date;
      $sitemap_content .= '<url>' . "\n";
      $sitemap_content .= '<loc>' . $url . '</loc>' . "\n";
      $sitemap_content .= '<lastmod>' . $modified . '</lastmod>' . "\n";
      $sitemap_content .= '</url>' . "\n";
      $url_count++;
      if ($url_count >= $max_urls) {
        $file_count++;
        $sitemap_content .= '</urlset>';
        $file = fopen('wp-sitemap-' . $file_count . '.xml', 'w');
        fwrite($file, $sitemap_content);
        fclose($file);
        $sitemap_content = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
        $sitemap_content .= '<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
        $url_count = 0;
      }

    where am i wrong?
    Thanks a lot

    wpsolr
    Keymaster
    10 months, 3 weeks ago #34370

    We only support official WPSOLR hooks. Other usage of internal code is not supported.

    matteo.cattelan
    Participant
    10 months, 3 weeks ago #34404

    I understand but I’m simply asking if there are any exposed functions that I can use to query the opensearch index.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.