hi i am new to wordpress. so i am getting lot of problems
I am trying to display posts of specific category using the following code

<?php
$cat=$_GET["cat"];
$args=array('category'=>$cat);
$posts_array = get_posts( $args );
foreach($posts_array as $posting)
{
echo $posting;
}
?> 

But i am getting errors instead. Please anyone help me in getting the solution. Thanks in advance

Hi,

Do you want to show them outside of the wordpress universe?, or are trying to create your own plugins?

Using wordpress docs as referenced here, we can easily device simple codes to retrieve and sort blog posts.

Example codes below is outside the wordpress. If you will be using it creating a plugin, the approach and coding techniques is slightly different.

include_once('wp-load.php');

global $post;

$cat = $_GET['cat'];
$how_many_post = 5; //change the number if you want more

$args = array( 'posts_per_page' => $how_many_post, 'category' => $cat);
$posts_array = get_posts( $args );

foreach($posts_array as $posting) : setup_postdata( $post );
{
  echo '<a href="'. the_permalink() .'">'. the_title() .'</a>';
}

it should work, but I have never had the chance to test it...

hi,

ERRATA!

change this

foreach($posts_array as $posting) : setup_postdata( $post );

to this

foreach($posts_array as $post) : setup_postdata( $post );

Sorry for the typos.