0

In my WordPress custom post type loop only want to pull in from three posts 5171, 5167 and 5165.

If I do:

'post__in' => array(5171,5167,5165),

The loop outputs the values for those three correctly.

If I do:

'post__in' => array($my_share),

It only outputs the values for 5171. However $my_share equals 5171,5167,5165. If I do echo $my_share it also shows 5171,5167,5165.

Is there any obvious reason why $my_share is only passing the first value into the post__in array or anyway around that issue?

1 Answer 1

3

If $my_share echoes as "5171,5167,5165" then it is a string not an array...

In other words array($string) does not equal array(integer,integer,integer) even if $string equals "integer,integer,integer" because array treats $string as a single value with further values separated by commas.

You could use post__in => explode(",", $my_share), to convert the string into an array while passing it... otherwise you could try just using post__in => $my_share, and it might be converted into an array for you (but not sure without delving deep into the code to look.)

1
  • Live saver! Continued searching and actually ended up finding, "explode(",", $my_share)" however passed over it since I tried doing, array(explode(",", $my_share)) which of course didn't work, and now makes better sense why. Thanks so much!!
    – cchiera
    Jul 19, 2017 at 2:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.