0

In my template, in the functions file, a developer created a code to show the last posts of various blogs (wp mu) on the homepage. I would like to edit the code by showing the pages in place of the posts.

I'll show parts of the code where I think it is necessary to replace somewhere the word post with page.

Can you help me to find out where and how? Thanks!

    add_shortcode( 'newswpmu', 'newswpmu_func' );
function newswpmu_func( $atts, $content = null ) { // New function parameter $content is added!
    global $post;

   extract( shortcode_atts( array(
      'title' => 'blog title',
      'blogid' => 1,
      'format' => 3,
      'show' => 3,
      'sortby' => "lastest",
      'exlength' => 100,
      'meta' => "",
      'readmore' => 'disabled',
      'seeall' => 'enabled',
      'seeall_link' => '',
      'seeall_text' => 'see all',
      'classes' => '',
      'format_medium' => 2,
   ), $atts ) );

   $content = wpb_js_remove_wpautop($content, true); // fix unclosed/unwanted paragraph tags in $content
   //print_r($post);

(...)

// show list articles
wp_reset_query();
switch_to_blog($blogid);

$my_query = new WP_Query('showposts='.$show.'&orderby= ' . $orderby . '&order=' . $order);
$articlecount = 0;
$articlecontent = "";
$get_meta_content = "";
while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID;
    $articlecount ++;

    $thumb_url = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'full');
    $image_url_small = str_replace(".jpg", "-350x175.jpg", $thumb_url[0]);
    $image_url_big = str_replace(".jpg", "-600x300.jpg", $thumb_url[0]);

(...)

    $articlecontent .= '

    <article class="post-item  post-' . get_the_ID() . ' post type-post status-publish format-standard has-post-thumbnail" itemscope="" itemtype="http://schema.org/Article">
        <meta itemprop="datePublished" content="' . get_the_date(get_option('date_format')) . '">
            <div class="gp-post-thumbnail featured-content image-above">
                <a href="' . get_the_permalink() . '" title="' . get_the_title() . '">
                    <img src="' . $image_url_small . '" data-rel="' . $image_url_big . '" alt="' . get_the_title() . '" class="wp-post-image" itemprop="image" height="150" width="300">
                </a>
            </div>
            <div class="post-item-content image-above">
  • Let me know if you need something else! – Cristian Aug 17 '17 at 16:38
  • Hi. Please try and add &post_type=page to the end of your new WP_Query() and see if it helps. – Jack Johansson Aug 17 '17 at 17:13
0

This was already answered in the comment by Jack, but what you would do is add &post_type=page at the end of the WP_Query call.

https://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters

Your revised query call:

$my_query = new WP_Query('showposts='.$show.'&orderby= ' . $orderby . '&order=' . $order . '&post_type=page');
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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