# Wp\_query from ajax editor

**URL:** <https://www.phphelp.com/t/wp-query-from-ajax-editor/33529>\
**Category:** Help with WordPress\
**Created:** [May 20, 2021, 7:13pm UTC](https://www.phphelp.com/t/wp-query-from-ajax-editor/33529 "2021-05-20T19:13:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![trtlator](https://www.phphelp.com/user_avatar/www.phphelp.com/trtlator/32/3715_2.png) [@trtlator](https://www.phphelp.com/u/trtlator)\
**Post date:** [May 20, 2021, 7:13pm UTC](https://www.phphelp.com/t/wp-query-from-ajax-editor/33529/1 "2021-05-20T19:13:21Z")

</div>

Hi I have a query that I would like to pull a random post and then ticker tape the name and url across the screen. I have everything working but I cannot get a spacing added to the exploded array from wp\_query

> **[random post title on ticker - Pastebin.com](https://pastebin.com/ZeB8HtyV)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

[https://startlivingpodcast.com/](https://startlivingpodcast.com/)

Thank you in advanced this is my first foray into php

---

<div class="post-metadata">

**Author:** ![skawid](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/bbe5ce/32.png) [@skawid](https://www.phphelp.com/u/skawid)\
**Post date:** [May 20, 2021, 7:22pm UTC](https://www.phphelp.com/t/wp-query-from-ajax-editor/33529/2 "2021-05-20T19:22:17Z")

</div>

```php
if($random_post -> have_posts() ) {
    while($random_post -> have_posts() ) {
        $random_post -> the_post();
        $listed='<a href="'.get_the_permalink().'">'.get_the_title().'</a>';
        $pieces = explode(" " ,"$listed");
        echo $pieces[0],$pieces[1],$pieces[2],$pieces[3];
    }
}

```

This snippet makes it look like you have yourself a little crossed up. I assume you want a different link for each item? If that’s what you want, you can write it like so:

```php
if ($random_post->have_posts() ) {
    while ($random_post->have_posts() ) {
        $random_post->the_post();
        echo '<div class="ticker-item"><a href="'.get_the_permalink().'">'.get_the_title().'</a></div>';
    }
}

```

The `while` loop will run once for each post in your list. You want to print out a link for each item in the list, so that’s all you do.

---

<div class="post-metadata">

**Author:** ![trtlator](https://www.phphelp.com/user_avatar/www.phphelp.com/trtlator/32/3715_2.png) [@trtlator](https://www.phphelp.com/u/trtlator)\
**Post date:** [May 20, 2021, 7:24pm UTC](https://www.phphelp.com/t/wp-query-from-ajax-editor/33529/3 "2021-05-20T19:24:17Z")

</div>

oh I see surrounding it in the div class will separate it  
that’s interesting thanks

---

<div class="post-metadata">

**Author:** ![skawid](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/bbe5ce/32.png) [@skawid](https://www.phphelp.com/u/skawid)\
**Post date:** [May 20, 2021, 7:38pm UTC](https://www.phphelp.com/t/wp-query-from-ajax-editor/33529/4 "2021-05-20T19:38:24Z")

</div>

No problem. As an aside: Noone wants to see a ticker tape on a website 🙂

There was a tag explicitly for doing this - [the marquee tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/marquee) - but it’s being removed from the standard. Noone wants to chase content around the screen to read or click on it.
