'Loop through all urls of the links posted in a post (WordPress)

I have a loop that gets the content of a post from a custom post type. The content of this specific post has some links to external images that I want to show in a lightbox - of course one after another:

`

    $args = array(
        post_type => 'xyz',
        'p' => 128

    );

    $custom_loop = new WP_Query($args);
    if ( $custom_loop->have_posts() ) : while ( $custom_loop->have_posts() ) : $custom_loop->the_post(); ?>
    <a href="<?php * what do I have to enter here * ?>">
    <h2><?php the_title();?></h2>
    <img src="def">
    </a>
     <?php endwhile; else : ?>
        <?php get_template_part('template_parts/content','error');?>
    <?php endif; wp_reset_postdata(); ?>`

The problem is: How can I loop through all the urls of all the links provided in the post? I only know this: wp_get_attachment_url();

But I don't want the url of an attached image, I only want the urls of the links that are listed in the post. In the frontend, the images provided by these links should be displayed in a lightbox after one clicks on the link which consists of the title of the post (h2) and a thumbnail (img). That's the plan :-)

Maybe I need a loop inside that loop that loops only through the links in the post? You see, I'm completely lost :-D Thx for any ideas!



Solution 1:[1]

@Omar Tani: Unfortunaltely, I was not able to make this code work for me. Therefore, I have used a meta box for each url which is then called in the code using the following code:

<?php $... = get_post_custom( $post->ID ); ?>

<a href="<?php echo $...["image1"][0]; ?>">

etc.

Thx anyway for your help!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Raul76