Support » Fixing WordPress » WP_Query get post IDs from list of slugs

  • I’m very new to WordPress & overall coding. I’m changing the current Similar Products on the single product pages to a selectable list and I’ve been trying to use a list of slugs from our products to post IDs, but I only found how to do it with an array of post IDs. How do I convert a list of slugs inputted on the editing page for each product to an array or post IDs? Below is the query I’ve been using.

    $pc = new WP_Query( array(
    'post_type' => 'any',
    'post__in' => array( 6036, 6127 ),
    'post_status' => 'publish',
    'orderby'=>'title',
    'order'=>'ASC'
    ) );

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hey George, WP_Query doesn’t support passing a list of slugs as far as I know. What about grabbing the IDs in your select list instead of slugs?

    Maybe I confused you a bit with the script I pasted. I want to enter an array of IDs into the query above. Grabbing the IDs from the slugs is what I’m trying to do, but don’t know how to get an array of IDs from a the list of slugs. The list of slugs would be entered in a text box and would look something like this, HL-300, HL-310, HL-360.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP_Query get post IDs from list of slugs’ is closed to new replies.