Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. $tag_string = '';
  2.  
  3. for ($i = 0; $i < 8; $i++) {
  4. for ($j = 0; $j < 8; $j++) {
  5.  
  6. $tag_to_use = get_post_meta($post->ID, '_tag_to_use_'.$i.'_'.$j, true);
  7. $tag_string = $tag_to_use ? $tag_string .= $tag_to_use . ',' : $tag_string .= '';
  8.  
  9. }
  10. }
  11.  
  12. if ( substr( $tag_string, -1) == ',' ) {
  13. $tag_string = rtrim( $tag_string, ',' );
  14. }
  15.  
  16. echo do_shortcode( '[products tag="' . $tag_string . '"]' );
  17.  
  18. }
  19.  
  20. echo do_shortcode( '[products tag="' . $tag_string . '"]' );
  21.  
  22. echo do_shortcode( '[products tag="test,test1"]' );
  23.  
  24. $post_meta = get_post_meta($post->ID); // This returns an array with all the data in position 0, if I remember correctly
  25. for ($i = 0; $i < 8; $i++) {
  26. for ($j = 0; $j < 8; $j++) {
  27. if ( isset( $post_meta[0]['_tag_to_use_'.$i.'_'.$j] ) ) {
  28. $tag_to_use = $post_meta[0]['_tag_to_use_'.$i.'_'.$j];
  29. // The meta value might be in a array with the position 0, var_dump $tag_to_use to see if this is the case
  30. // $tag_to_use = $post_meta[0]['_tag_to_use_'.$i.'_'.$j][0];
  31. $tag_string = $tag_to_use ? $tag_string .= $tag_to_use . ',' : $tag_string .= '';
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement