add filter not working when cancatenating variables

I am getting a problem while applying a code. My code works fine when i use only one variable. e.g;

$posts_per_page = ‘posts_per_page=3’;

but it doesn’t work if i use concatenation.e.g

$posts = “posts_per_page=”;
$number = 3;
$posts_per_page = $posts. $number;

my full code looks like .

function blogs() {?>
<article>

<?php // Display blog posts on any page @ https://m0n.co/l
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$posts = ‘post_per_page=’;
$number = 3;
$posts_per_page = $posts . $number ;
$wp_query->query( apply_filters(‘change_number_of_posts_home’, $posts_per_page) . ‘&paged=’.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

<h2><a href=”<?php the_permalink(); ?>” title=”Read more”><?php the_title(); ?></a></h2>
<?php openblogger_posted_on();
openblogger_posted_by(); ?>

<?php endwhile; ?>

<?php wp_reset_postdata(); ?>

</article>
<?php
}

Can anyone tell me why the doesn’t work. Also, i am trying to use filter for $number = 3; so that user can change the number easily.
Thanks in advance.

Read more here:: add filter not working when cancatenating variables

Leave a Reply

Your email address will not be published. Required fields are marked *