WP_Query get post IDs from list of slugs (3 posts)

  1. georgegeorge
    Posted 3 years ago #

    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',
    ) );

  2. Andrew Bartel
    Posted 3 years ago #

    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?

  3. georgegeorge
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic