I'm trying to modify the Object that returns the result of WP_Query
to add fake posts (which are actually news that feed on a RSS
parsed), and I'm stuck on it ..
Let's see if I explain myself a little better. I have this:
$posts = new WP_Query($args);
//$posts->posts trae 2 paginas reales creadas en el WP pero quiero agregar 10 paginas mas que la parseo en $xml
That is, if I make a print_r
of $posts
it brings this:
WP_Query Object
(
[query] => Array
(
[offset] => 0
[posts_per_page] => 12
[post_type] => post
[post_status] => publish
[orderby] => date
[order] => DESC
)
[query_vars] => Array
(
[offset] => 0
[posts_per_page] => 12
[post_type] => post
[post_status] => publish
[orderby] => date
[order] => DESC
[error] =>
[m] =>
[p] => 0
[post_parent] =>
[subpost] =>
[subpost_id] =>
[attachment] =>
[attachment_id] => 0
[name] =>
[static] =>
[pagename] =>
[page_id] => 0
[second] =>
[minute] =>
[hour] =>
[day] => 0
[monthnum] => 0
[year] => 0
[w] => 0
[category_name] =>
[tag] =>
[cat] =>
[tag_id] =>
[author] =>
[author_name] =>
[feed] =>
[tb] =>
[paged] => 0
[meta_key] =>
[meta_value] =>
[preview] =>
[s] =>
[sentence] =>
[title] =>
[fields] =>
[menu_order] =>
[embed] =>
[category__in] => Array
(
)
[category__not_in] => Array
(
)
[category__and] => Array
(
)
[post__in] => Array
(
)
[post__not_in] => Array
(
)
[post_name__in] => Array
(
)
[tag__in] => Array
(
)
[tag__not_in] => Array
(
)
[tag__and] => Array
(
)
[tag_slug__in] => Array
(
)
[tag_slug__and] => Array
(
)
[post_parent__in] => Array
(
)
[post_parent__not_in] => Array
(
)
[author__in] => Array
(
)
[author__not_in] => Array
(
)
[ignore_sticky_posts] =>
[suppress_filters] =>
[cache_results] => 1
[update_post_term_cache] => 1
[lazy_load_term_meta] => 1
[update_post_meta_cache] => 1
[nopaging] =>
[comments_per_page] => 50
[no_found_rows] =>
)
[tax_query] => WP_Tax_Query Object
(
[queries] => Array
(
)
[relation] => AND
[table_aliases:protected] => Array
(
)
[queried_terms] => Array
(
)
[primary_table] => wp_posts
[primary_id_column] => ID
)
[meta_query] => WP_Meta_Query Object
(
[queries] => Array
(
)
[relation] =>
[meta_table] =>
[meta_id_column] =>
[primary_table] =>
[primary_id_column] =>
[table_aliases:protected] => Array
(
)
[clauses:protected] => Array
(
)
[has_or_relation:protected] =>
)
[date_query] =>
[request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND ((wp_posts.post_status = 'publish')) ORDER BY wp_posts.post_date DESC LIMIT 0, 12
[posts] => Array
(
[0] => WP_Post Object
(
[ID] => 88
[post_author] => 1
[post_date] => 2017-08-08 07:27:25
[post_date_gmt] => 2017-08-08 07:27:25
[post_content] => Hola Esto es un Loren
[post_title] => Lo he Encontrado
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => lo-he-encontrado
[to_ping] =>
[pinged] =>
[post_modified] => 2017-08-28 16:22:12
[post_modified_gmt] => 2017-08-28 16:22:12
[post_content_filtered] =>
[post_parent] => 0
[guid] => https://www.midominio.com/?p=88
[menu_order] => 0
[post_type] => post
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
[1] => WP_Post Object
(
[ID] => 58
[post_author] => 1
[post_date] => 2017-08-03 11:26:42
[post_date_gmt] => 2017-08-03 11:26:42
[post_content] => Texto en el Content
[post_title] => Loren Ipsum Noticia
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => sluggggggg
[to_ping] =>
[pinged] =>
[post_modified] => 2017-08-28 16:22:12
[post_modified_gmt] => 2017-08-28 16:22:12
[post_content_filtered] =>
[post_parent] => 0
[guid] => https://www.midominio.com/?p=58
[menu_order] => 0
[post_type] => post
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
//////////////////////////////////////////////////////////////////////////////////////////////////
// QUIERO AÑADIR MAS REGISTROS ACA DESDE UNA FUENTE EXTERNA COMO XML QUE LO PARSEO A ARRAY
//////////////////////////////////////////////////////////////////////////////////////////////////
)
[post_count] => 2
[current_post] => -1
[in_the_loop] =>
[post] => WP_Post Object
(
[ID] => 88
[post_author] => 1
[post_date] => 2017-08-08 07:27:25
[post_date_gmt] => 2017-08-08 07:27:25
[post_content] => Hola Esto es un Loren
[post_title] => Lo he Encontrado
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => lo-he-encontrado
[to_ping] =>
[pinged] =>
[post_modified] => 2017-08-28 16:22:12
[post_modified_gmt] => 2017-08-28 16:22:12
[post_content_filtered] =>
[post_parent] => 0
[guid] => https://www.midominio.com/?p=88
[menu_order] => 0
[post_type] => post
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
[comment_count] => 0
[current_comment] => -1
[found_posts] => 2
[max_num_pages] => 1
[max_num_comment_pages] => 0
[is_single] =>
[is_preview] =>
[is_page] =>
[is_archive] =>
[is_date] =>
[is_year] =>
[is_month] =>
[is_day] =>
[is_time] =>
[is_author] =>
[is_category] =>
[is_tag] =>
[is_tax] =>
[is_search] =>
[is_feed] =>
[is_comment_feed] =>
[is_trackback] =>
[is_home] => 1
[is_404] =>
[is_embed] =>
[is_paged] =>
[is_admin] =>
[is_attachment] =>
[is_singular] =>
[is_robots] =>
[is_posts_page] =>
[is_post_type_archive] =>
[query_vars_hash:WP_Query:private] => eece7ee429fd38bda3abe3ac6b0c63da
[query_vars_changed:WP_Query:private] =>
[thumbnails_cached] =>
[stopwords:WP_Query:private] =>
[compat_fields:WP_Query:private] => Array
(
[0] => query_vars_hash
[1] => query_vars_changed
)
[compat_methods:WP_Query:private] => Array
(
[0] => init_query_flags
[1] => parse_tax_query
)
)
Now if I try with:
foreach ($xml as $noticia) {
$posts->found_posts = count($noticia);
foreach ($noticia as $key => $value) {
$idNoticia = $value['idNoticia'];
$titulo=$value['title'];
$link=$value['url'];;
$descripcion = $value['description'];
$descripcion_corta = $value['description_corta'];
$fechanoticia = strftime("%d-%b-%Y", strtotime($value['data']));
$posts->posts[$key]->ID = $idNoticia;
$posts->posts[$key]->post_title = $titulo;
$posts->posts[$key]->post_content = $descripcion;
$posts->posts[$key]->post_excerpt = $descripcion_corta;
$posts->posts[$key]->post_date = $fechavc;
$posts->posts[$key]->post_date_gmt = $fechavc;
$posts->posts[$key]->post_modified = $fechavc;
$posts->posts[$key]->post_modified_gmt = $fechavc;
$posts->posts[$key]->post_name = sanitize_title_with_dashes($titulo);
$posts->posts[$key]->guid = $link;
$posts->posts[$key]->post_type = 'post';
$posts->posts[$key]->post_author = 1;
$posts->posts[$key]->post_status = 'publish';
$posts->posts[$key]->comment_status = 'closed';
$posts->posts[$key]->ping_status = 'closed';
$posts->posts[$key]->to_ping = '';
$posts->posts[$key]->pinged = '';
$posts->posts[$key]->post_content_filtered = '';
$posts->posts[$key]->post_parent = 0;
$posts->posts[$key]->menu_order = '';
$posts->posts[$key]->post_mime_type = '';
$posts->posts[$key]->comment_count = 0;
$posts->posts[$key]->filter = 'raw';
}
}
After adding them, when doing print_r($posts->posts)
if you show them to me but type stdClass Object
, but it does not work, below when doing the render of the grid it does not show these new aggregates.
I was reading but they talk about an action called pre_get_posts
, but I honestly do not know where to start regarding this.