I want to transfer $linker_sluger from function which create page to function which create gallery, but when i make it as global and try transfer it, it's clear.

function page_creator(){
global $wpdb, $ling, $slugerr, $linker_sluger, $tester;
$linker_sluger= $ling.'/'.$slugerr;

$poster_id = $wpdb ->get_results("SELECT ID from wp_posts WHERE post_status='publish' AND post_type='post' ORDER BY ID DESC");

foreach ($poster_id as $posters_id){

    global $post;
    $post = get_post($posters_id->ID);

    $galleries_counter = get_post_galleries($post, false );
    $total_gal = count( $galleries_counter );

    $ile_fotek = _get_total_images($galleries_counter );

    if(has_shortcode( $post->post_content, 'gallery' ) && $ile_fotek<1){
        echo"za malo fotek mniej niz ".$ile_fotek;
    elseif(has_shortcode( $post->post_content, 'gallery' )){
        echo "FOTKIbb: ".$ile_fotek;
        if (is_page(376)){
            echo'<div class="single-album col-md-3 col-sm-12">';
            echo na_get_gallery_image_urls($posters_id->ID); 
            echo '</div>';
            $galeryjka =  na_get_gallery_image_urls($posters_id->ID);

            $title = get_the_title($post);
            $Poster = new PostController;
            $Poster->set_content("[insert_php]na_get_gallery_image_urls($posters_id->ID);[/insert_php]" );
            $Poster->set_author_id( 1 );
            $sluger = $Poster->set_post_slug("albums-inside-".$title);
            $Poster->set_page_template( "page-single-gallery.php" );
            $Poster->set_post_state( "publish" );
            $Poster->search('title', 'Old Post');
            $ling = get_home_url();
            $slugerr = sanitize_title($sluger, '', 'save');
            $linker_sluger = $ling.'/'.$slugerr;   // transfer this $linker_sluger to bottom function, but when try it clear

            echo'<div class="col-md-12 col-sm-12">';
            echo na_get_gallery_image_urls($posters_id->ID);
            echo '</div>';



function na_get_gallery_image_urls( $post_id ) {
global $wpdb, $linker_sluger, $ling, $slugerr, $tester;
$post = get_post($post_id);

// Make sure the post has a gallery in it
if( ! has_shortcode( $post->post_content, 'gallery' ) )

// Retrieve all galleries of this post
$galleries = get_post_galleries_images( $post );
$title = get_the_title($post_id);

//$poster_guid = $wpdb->get_results("SELECT guid from wp_posts WHERE post_name LIKE ('albums-inside-%') ORDER BY guid DESC");
echo '<h3>'. $title .'</h3>'; 

// Loop through all galleries found
foreach( $galleries as $gallery ) {
    // Loop through each image in each gallery
        foreach( $gallery as $image) {

            if(is_page( 376 )){
                echo '<div class="single-image page-gallery col-md-12 col-sm-12">';
                echo '<a href="'.$linker_sluger.'"><img src="'.$image.'"></a>';
                echo '</div>';


            elseif(is_page( 5 )){
                echo '<div class="single-image page-home col-md-12 col-sm-12">';
                echo '<a href="'.$linker_sluger.'"><img src="'.$image.'"></a>';
                echo '</div>';


                echo '<div class="single-image page-inside-gallery col-md-3 col-sm-12">';
                echo '<a class="foobox" rel="gallery" href="'.$image.'"><img src="'.$image.'"></a>';
                echo '</div>';  


closed as unclear what you're asking by Jacob Peattie, fuxia Aug 7 at 12:17

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


Whatever happens in your function (I didn't look deep in it) you can pass more then one parameter if you call the function

na_get_gallery_image_urls($posters_id->ID, $linker_sluger);

and use the value.
But makes it sense? Once you put an echo in a variable $galeryjka and then you echo the echo?

  • it almost ok, the newest(first) image don't have any href, penultimate(second) has href of first, and the last has href of second – ncti Aug 7 at 13:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.