The above logic will get the $url from the latest posts, but there is quiet a possibility that the latest posts may not have the URL than I want that it should look for the second latest, or third latest and so on… and as soon as it find sthe URL the loop should terminate.
Some PHP is involved, but I am unable to do this. Please help me.
Edit:
If you want to break out of the while loop add this condition:
</php
//
while ( $the_query->have_posts() ) :
// do your stuff here before possible break
if( $condition === TRUE):
break;
endif;
// or do your stuff here after the possible break
endwhile;
I want that loop should run until it finds a first valid non-empty $url that means as soon as it finds a valid $url the loop should terminate. It should keep running until it finds the first valid non-empty URL.
How should we condition it to get what i want?
N.B. → Loop should work from the latest post to the oldest post.
Valid URL means it has a video URL such as youtube, vimeo etc.
[offtopic]
Why are you repeatedly opening and closing PHP?
It is far more readable to just open PHP once and even better to echo HTM: scripts.
Or is it just me that has difficulty reading your scripts?
[/offtopic]
That example has HTML code between each line of PHP. Yours does not. In your example code in post #8, the continual opening and closing on each line is not required because all that code is PHP. All it really does is make it harder to read.
Sure, when you’re needing to send HTML out, then you either have to come “out” of PHP to do it, or use echo() and have your PHP output it, and the choice will depend on the exact circumstances.