I made it work
Although it requires a lot of file editing. I will add my changes below, it works for me.
Make the script load post from correct category:
js.php
Find
var isFirstFrontPage = <?php echo $page_options['is_first_front_page'] ?>;
var isFrontPage = <?php echo $page_options['is_front_page'] ?>;
Replace with
var isFirstFrontPage = <?php echo 1 //$page_options['is_first_front_page'] ?>;
var isFrontPage = <?php echo 1 //$page_options['is_front_page'] ?>;
var thecategoryid = <?php
if($page_options['is_front_page']!=1){
$category11 = get_the_category();
echo $category11[0]->cat_ID;
}else{
echo "false";
}
?>;
p2.js
Correct js category query, around line 107
var queryString = ajaxUrl +'&action=get_latest_posts&load_time=' + pageLoadTime + '&frontpage=' + isFirstFrontPage+ '&thecategoryid=' + thecategoryid;
ajax.php
Correct database query
Replace function get_latest_posts()
function get_latest_posts() {
$load_time = $_GET['load_time'];
$frontpage = $_GET['frontpage'];
$thecategoryidunsafe = $_GET['thecategoryid'];
$thecategoryid = filter_var($thecategoryidunsafe, FILTER_SANITIZE_NUMBER_INT);
if (is_numeric ($thecategoryid )){
$catquer = "&cat=$thecategoryid";
}
$num_posts = 10; // max amount of posts to load
$number_of_new_posts = 0;
query_posts('showposts=' . $num_posts . '&post_status=publish'.$catquer);
ob_start();
while (have_posts()) : the_post();
$current_user_id = get_the_author_meta( 'ID' );
if ( get_gmt_from_date( get_the_time( 'Y-m-d H:i:s' ) ) <= $load_time ) continue;
$number_of_new_posts++;
$post_request_ajax = true;
require dirname(__FILE__) . '/../entry.php';
endwhile;
$posts_html = ob_get_clean();
if ( $number_of_new_posts != 0 ) {
nocache_headers();
echo json_encode( array(
'numberofnewposts' => $number_of_new_posts,
'html' => $posts_html,
'lastposttime' => gmdate('Y-m-d H:i:s')
) );
} else {
header("HTTP/1.1 304 Not Modified");
}
}
I also need multiple categories per post, the p2-theme does not do this out of the box.
Make the postform post “post_cat” in this format: “cat1,cat2,cat3” That’s easy so I wont write that here.
Then you need to make the p2-theme support multiple categories per post.
ajax.php
My solution:
//snip
/* $accepted_post_cats = apply_filters( 'p2_accepted_post_cats', array( 'post', 'quote', 'status', 'link' ) );
$post_cat = ( in_array( $_POST['post_cat'], $accepted_post_cats ) ) ? $_POST['post_cat'] : 'post'; */
$post_cat = filter_input(INPUT_POST, 'post_cat' , FILTER_SANITIZE_SPECIAL_CHARS);
$post_cat = explode(",",$post_cat);
$catids = array();
foreach($post_cat as $singlecat){
if ( !category_exists( $singlecat ) )
wp_insert_category( array( 'cat_name' => $singlecat ) );
$singlecat = get_category_by_slug( $singlecat );
array_push($catids,$singlecat->cat_ID);
}
/* Add the quote citation to the content if it exists */
if ( !empty( $_POST['post_citation'] ) && 'quote' == $post_cat->slug ) {
$post_content = '<p>' . $post_content . '</p><cite>' . $_POST['post_citation'] . '</cite>';
}
$post_id = wp_insert_post( array(
'post_author' => $user_id,
'post_title' => $post_title,
'post_content' => $post_content,
'post_type' => $post_type,
'post_category' => $catids,
//snip
I think that’s all, good luck!