• Resolved Melusine29

    (@melusine29)


    Hi

    I get my custom post on my 2nd WordPress website via switch_to_blog(2) but suddenly it does not return me the right url and pagination and the “read more”. I would stay on my main site.

    How is this possible?

    Thank’s in advance

Viewing 11 replies - 1 through 11 (of 11 total)
  • Sounds like you are using the switch_to_blog function within a loop. You need to switch to the blog first and then start your loop.

    Thread Starter Melusine29

    (@melusine29)

    I do the switch_to_blog into the loop. My code :

    while(have_posts()): the_post();
    	switch_to_blog(2); // Annonces
    	if(get_query_var('paged')){ $paged = get_query_var('paged'); }else if(get_query_var('page')){ $paged = get_query_var('page'); }else{ $paged = 1; }
    	$args = array(
    		'post_type'			=> 'agences',
    		'posts_per_page'	=> 8,
    		'order'				=> 'DESC',
    		'orderby'			=> 'post_date',
    		'paged'				=> $paged,
    		'suppress_filters'	=> false,
    	);
    	query_posts($args);
    	if(have_posts()):
    		while(have_posts()): the_post();
    			echo '<h4>'.get_post_meta($post->ID, 'cpt_ville', true).' ('.get_post_meta($post->ID, 'cpt_departement', true).')</h4>
    			<span class="adr displayib">'.get_the_title().'<br/>
    			<a href="'.get_page_link().'" class="btn-fiche btn-more"><span></span>Voir la fiche</a>';
    		endwhile;
    		wp_pagenavi();
    	endif;
    	wp_reset_query(); // Reset Query
    	restore_current_blog();
    endwhile;

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    šŸ³ļøā€šŸŒˆ Advisor and Activist

    You need to switch to the blog first and then start your loop.

    That is correct. You’re looking for posts BEFORE you switch blogs, which is a Schroedinger condition šŸ™‚

    Thread Starter Melusine29

    (@melusine29)

    this is what I do, not?

    switch_to_blog(2); // Annonces
    if(get_query_var('paged')){ $paged = get_query_var('paged'); }else if(get_query_var('page')){ $paged = get_query_var('page'); }else{ $paged = 1; }
    $args = array(
    	'post_type'			=> 'agences',
    	'posts_per_page'	=> 8,
    	'order'				=> 'DESC',
    	'orderby'			=> 'post_date',
    	'paged'				=> $paged,
    	'suppress_filters'	=> false,
    );
    query_posts($args);
    if(have_posts()):
    	while(have_posts()): the_post();
    		echo '<h4>'.get_post_meta($post->ID, 'cpt_ville', true).' ('.get_post_meta($post->ID, 'cpt_departement', true).')</h4>
    		<span class="adr displayib">'.get_the_title().'<br/>
    		<a href="'.get_page_link().'" class="btn-fiche btn-more"><span></span>Voir la fiche</a>';
    	endwhile;
    	wp_pagenavi();
    endif;
    wp_reset_query(); // Reset Query
    restore_current_blog();

    what is wrong?

    Ryan Kanner

    (@ryankanner)

    You should be using get_permalink() instead of get_page_link()

    Thread Starter Melusine29

    (@melusine29)

    This is the same problem. I do my switch_to_blog() to my 2nd WordPress instance but the links I want to stay on my first instance.

    Is that possible?

    Ryan Kanner

    (@ryankanner)

    You would have to do that with a separate query, or with a static link. You could also store a link location in a variable before you use the switch_to_blog function and use that, which could make it a bit more dynamic. Though I don’t know why you would want to link your read more to something other than the post.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    šŸ³ļøā€šŸŒˆ Advisor and Activist

    I do my switch_to_blog() to my 2nd WordPress instance but the links I want to stay on my first instance.

    Huh? You want to switch to blog 2 and get data from blog 1?

    Thread Starter Melusine29

    (@melusine29)

    Huh? You want to switch to blog 2 and get data from blog 1?

    No, I switch to the blog 2 to retrieve information from the 2, but I want the permalink for each post reference to a single blog 1.

    This is possible with an otherwise redirect? refer to a template-agence.php page for example?

    Ryan Kanner

    (@ryankanner)

    No, I switch to the blog 2 to retrieve information from the 2, but I want the permalink for each post reference to a single blog 1.

    If I am understanding correctly you want ALL of the posts that you are grabbing from blog2 to link to the SAME url which is on blog1?

    If that’s the case, just store the URL you want all of the posts to go to in a variable before you use switch_to_blog() and then just use your stored url variable in place of get_page_link()

    Thread Starter Melusine29

    (@melusine29)

    Hi

    I tried several ways but it does not work .. I will do again on a single WordPress installation, it will be less headaches.

    Thank you for your help anyway!

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Error on URL’ is closed to new replies.