WordPress loop put title into variable

Creating variables on the fly like that is not needed. Just use an array instead. $myvars = []; inside your foreach loop you can: $myvars[] = array(‘title’=>$t,’image’=>$v); After your loop you can: //First title, First image echo $myvars[0][‘title’]; echo $myvars[0][‘image’]; //Second title, Second image echo $myvars[1][‘title’]; echo $myvars[1][‘image’]; This way you can always print_r($myvars) and … Read more

Parse error: syntax error, unexpected ‘endforeach’ (T_ENDFOREACH) in [closed]

When you use endforeach;, you have to use : instead off { when starting the foreach. <ul class=”project-extension-side-link”> <?php foreach($projectextensions as $projectextension) : // <— ?> <li <?php echo ($section==’project-extension’ ? ‘class=”active”‘: ”); ?>><span>Project 1</span></li> <li><a href=””><?php echo $projectextension->post_title; ?></a></li> <li><a href=””>Project 3</a></li> <li><a href=””>Project 4</a></li> <li><a href=””>Project 5</a></li> <li><a href=””>Project 6</a></li> <?php endforeach; ?> … Read more

pull 500 post of many from database [duplicate]

function posts_limits_set( $limit, $query ) { if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) { return ‘LIMIT 0, 100’; } return $limit; } add_filter( ‘post_limits’, ‘posts_limits_set’, 10, 2 );

how to handle multiple forloop?

You can do something like this public function getStuffDone() { $order_ids = array( 358,368 ); $items = array(); // contains the names foreach ( $order_ids as $order_id ) { $order = wc_get_order( $order_id ); foreach ( $order->get_items() as $item_values ) { $items[ $order_id ][] = $item_values->get_name(); // add the name to the array } } … Read more

Problem with ms-thumb-frame-selected class in Master Slider

Seems you are simply overwriting #masterslider .ms-thumb-frame-selected with each loop. So in the end only the last iteration will take effect. You maybe need to add the post ID as class somewhere as well and then target #masterslider .ms-thumb-frame-selected .post-<?php echo $post->ID; ?> { } in your CSS. Adjust your markup inside The Loop to … Read more

For each loop will not append to the_content hook

Filter should modify the given value and return it. It should not print anything. But your foreach loop does exactly opposite – it prints its output and doesn’t append anything to result. So when you use it to append its result to the content, it prints its result and doesn’t return anything – so nothing … Read more