wp query – how to fetch post_name from WP_Query using Group by a custom value field

Question

I’m trying to extract the post_name from this WP_Query in an effort to get the slug, I’m able to get the Title but not the post_name, I’m using get_post_field() to try to do so, but I seem to be missing a step. Here is my code so far.

$custom_posts = array();
$args = array(  
    'post_type' => 'windows',
    'post_status' => 'publish',
);

$latestData = new WP_Query($args);

 

  while ( $latestData->have_posts() )
    $slug = get_post_field('post_name', $recent->the_post);

      {
        $latestData->the_post();
        $title = get_the_title();
        $post_slug = get_post_field( 'post_name', get_post() );
        $value = get_field_object('windows_section');
        $field = $value['value'];
        $custom_posts[$field][$title]  = $post;
        $post_name[$field][$post_slug] = $post;
        
   }
 
 foreach($custom_posts as
 $field_post => $custom_title
 
 ) 
   
 {

    echo '<li><h3>' . $field_post . '</h3>';

    foreach($custom_title as $post_listing => $listing
    
    
    )
  
    
    {
        echo '<a href = "' . $post_name . '/"><p>' . $post_listing . '</p></a>';
    }
echo '  </li>';
}

 wp_reset_postdata();
;

0
Dennis 1 month 2022-10-26T20:10:48-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse