Support

Account

Home Forums General Issues Get a random item from a relationship field Reply To: Get a random item from a relationship field

  • Hi @matteo Balocco

    Your above code shows some mixed directions and doesn’t make too much sense looking at it.

    The best thing you can do is simplify the task into steps.

    Firstly, just get a random $post from the $posts array. Please read the above link I posted to find out how to do this.

    Once you have the random $post, you can then echo it’s title like this:

    
    echo get_the_title($post->ID)
    

    Just test your code line by line. Print out vars and debug the data.

    Good luck

    Thanks
    E