Support » Plugin: Multisite Language Switcher » Linking posts by code

  • PG

    (@parulgarg2)


    Hi

    Thanks for a wonderful plugin you have made!

    I am currently trying to switch my single site to multisite. I have a number of posts that I would like to link automatically through code. Is there any way to do that ?

    Also, I have an input to make. Since I am having an author based website, I don’t want them to be able to link their posts from other authors.. so in MslsMetaBox.php may be you can try and integrate ‘author’ as well in the query. Right now I have manually handled it, but afraid to have to do it every time there is an update.

    Thanks alot.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Dennis Ploetner

    (@realloc)

    Hello,

    thanks for your message.

    Is there any pattern that could be used to decide which posts should be tied together?

    For the request: Would you share some code to get the idea better?

    Cheers,
    Dennis

    PG

    (@parulgarg2)

    Hi

    Thanks for your reply.

    Yes, actually I have a custom post type that supports custom taxonomy country. Now when I am trying to move the single site to multisite, i have made different countries as different sites. I will run a script that will copy posts from the base site to their appropriate country’s site. In case of multiple countries, I needed to link them together.
    So, I was thinking of having site ids and post ids in hand; if I can link those posts together.

    For the request:
    This is what I have done in MslsMetaBox.php

    
    $query = array(
    	'post_type'      => $type,
    	'post_status'    => get_post_stati( [ 'internal' => '' ] ),
    	'orderby'        => 'title',
    	'order'          => 'ASC',
    	'posts_per_page' => - 1,
    	'fields'         => 'ids',
    	'author'         => ''
    );
    if ( is_admin() && !current_user_can('edit_others_posts')){
    	$query['author']=get_current_user_id();
    }
    
    $my_query = new \WP_Query($query);
    
    
    • This reply was modified 2 months, 1 week ago by PG.
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.