WordPress, result array of ‘post_name’

Question

when I try to run this array it doesn’t give me the exact results of the 4 slugs I want to get, but many more results come out:

$slugArray = array(

    'post_type' =>  'post',
    'post_status'       => 'publish',
    'post_name__in' => array( 'permalink1', 'permalink2', 'permalink3', 'permalink4' ),

);



 // Get all posts
$query = new WP_Query($slugArray);

$posts = $query->get_posts();

below I paste the script continuous to modify these slugs that I should insert in the array.

foreach ($posts as $post) {


    if($post) {


                    
    //if $post->post_name, (preg_match("/^([0-9]+)-(.*)/", $match))
        if(preg_match("/^([0-9]+)-(.*)/", $post->post_name, $match))
    $new_slug = (intval($match[1])+1) . "-" . $match[2];
        else
            $new_slug = "1-" . $post->post_name;

    // Prepare arguments
    $args = array(
        'ID' => $post->ID,          
        'posts_per_page' => 4,
        'post_name' => $new_slug,
    );
    // Update post
    //wp_update_post( $args );
        var_dump ($args);
}
}

?>

so i should just get:

array(3) { ["post_type"]=> string(4) "post" ["post_status"]=> string(7) "publish" ["post_name__in"]=> array(4) { [0]=> string(20) "permalink1" [1]=> string(30) "permalink2" [2]=> string(12) "permalink3" [3]=> string(22) "permalink4" }

but instead I get another 1000 different post_name results

0
tony9031 5 months 2020-12-29T09:10:23-05:00 0 Answers 5 views 0

Leave an answer

Browse
Browse