0

I have two different WordPress pages while the main site was developed under Laravel framework. Both WordPress sub-sites have different approach for the main site. It happens that the sub-site #1 was hooked to the main site and it display properly all the blog posts/custom posts. But when I tried to hooked the sub-site #2 to the main site, it still carry the posts of sub-site #1 and/or whenever I tried to set the "post_type" => "page_customs" it don't display the custom post I have there.

Here's the code i have for sub-site #1:

<?php require('site1/wp-load.php');
global $post;

$sticky = get_option( 'sticky_posts' );
rsort( $sticky );
$sticky = array_slice( $sticky, 0, 5 );
$args = array( 'post__in' => $sticky, 'ignore_sticky_posts' => 1, 'posts_per_page' => 5, 'order' => 'DESC' );
$query = new WP_Query( $args );
if ($query->have_posts()) : 
  while ($query->have_posts()) : 
    $query->the_post();

    $field = get_field_object('article_sticky_post');
    $value = $field['value'];
    $choices = $field['choices'];

    if ($value) :
        foreach ( $value as $v ) :
            $set = $v;
        endforeach;

      if($set == 'yes'): ?>

      <div class="listed-type-item _hide">
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?> | <span class="text-success small">Read more...</span></a>
      </div>

      <?php endif; // $set
    endif; // $value
  endwhile; 
endif; 
wp_reset_postdata(); ?>

While here's the code for sub-site #2:

<?php require('site2/wp-load.php');
global $post;

$args = array( 'post_type' => 'nas_customs', 'posts_per_page' => -1, 'order' => 'DESC' );
$query = new WP_Query( $args );
if ($query->have_posts()) :
  while ($query->have_posts()) :
    $query->the_post(); ?>

    <div class="listed-type-item _hide">
      <a href="<?php the_permalink(); ?>"><?php the_title(); ?> | <span class="text-success small">Read more...</span></a>
    </div>

  <?php endwhile; 
endif; 
wp_reset_postdata(); ?>

And it happens that the sub-site #1 content (page title) loads on sub-site #2.

5
  • Can you indent/format your code? It's difficult to read :(
    – Tom J Nowell
    Nov 9, 2018 at 23:19
  • Sorry about that, there I reformat the codes. Nov 9, 2018 at 23:45
  • hmmm where are these files, what are they named, and how are they loaded? You're sure that only one is ever loaded at an time? Never both?
    – Tom J Nowell
    Nov 10, 2018 at 2:38
  • both site1 & site2 wp folders are sub-folders of my laravel main site. site1 display various news and related blog posts, while site2, display investment pages relatively to the main site. though, I realized site2 was previously declared as sub-domain, could it be that the issue? Nov 10, 2018 at 9:59
  • No, but can you be more specific, is there ever a point when both files are loaded? Are those standalone files? Have you tested the WP installs themselves as WP installs ignoring these scripts and the Laravel stuff? Again, you can require('site1/wp-load.php') or require('site2/wp-load.php') but not both in the same request
    – Tom J Nowell
    Nov 10, 2018 at 12:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.