I am making a mobile application(Using Ionic Framework) of a news website which is made of wordpress . The json file is fetched from the site. I have to fetch same duplicate json data with some new posts from wordpress site for my app to show new news if a user continue to scroll. So I have to add/append these new several posts objects into the previous "posts" array of objects. Here is the conventional wordpress posts json file object looks like.
{
"status": "ok",
"count": 2,
"count_total": 4231,
"pages": 2116,
"posts": [
{
"id": 62296,
"type": "post",
"slug": "any slug",
"url": "any url",
"status": "publish",
"title": "any title",
"title_plain": "any title",
"content": "any content",
"excerpt": "any excerpt",
"date": "2015-02-26 02:08:57",
"modified": "2015-02-26 02:09:59",
"categories": [
{
"id": 1015,
"slug": "any slug",
"title": "any title",
"description": "",
"parent": 0,
"post_count": 7
}
],
"tags": [
{
"id": 1180,
"slug": "any slug",
"title": "any title",
"description": "",
"post_count": 6
},
{
"id": 1179,
"slug": "religion",
"title": "religion",
"description": "",
"post_count": 5
},
{
"id": 1209,
"slug": "any slug",
"title": "any title",
"description": "",
"post_count": 4
}
],
"author": {
"id": 1,
"slug": "newsdesk",
"name": "NewsDesk",
"first_name": "",
"last_name": "",
"nickname": "NewsDesk",
"url": "",
"description": ""
},
"comments": [],
"attachments": [
{
"id": 44930,
"url": "anything appropriate",
"slug": "anything appropriate",
"title": "anything appropriate",
"description": "",
"caption": "",
"parent": 62296,
"mime_type": "image/jpeg",
"images": {
"full": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"thumbnail": {
"url": "anything appropriate",
"width": 150,
"height": 147
},
"medium": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"large": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"tie-small": {
"url": "anything appropriate",
"width": 55,
"height": 55
},
"tie-medium": {
"url": "anything appropriate",
"width": 272,
"height": 125
},
"tie-large": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"slider": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"big-slider": {
"url": "anything appropriate",
"width": 290,
"height": 147
}
}
}
],
"comment_count": 0,
"comment_status": "open",
"thumbnail": "anything appropriate": {
"views": [
"2"
],
"taq_review_button_text": [
""
],
"taq_review_button_size": [
"medium"
],
"taq_review_button_shape": [
"square"
],
"taq_review_button_color": [
"#c7c7c7"
],
"taq_button_icon": [
"fa fa-check"
],
"taq_review_button_type": [
"flat"
],
"taq_review_button_url": [
""
],
"taq_review_title": [
""
],
"taq_review_position": [
""
],
"taq_review_style": [
"stars"
],
"taq_review_summary": [
""
],
"taq_review_total": [
""
],
"tie_hide_meta": [
""
],
"tie_hide_author": [
""
],
"tie_hide_share": [
""
],
"tie_hide_related": [
""
],
"tie_hide_check_also": [
""
],
"tie_sidebar_pos": [
"default"
],
"tie_sidebar_post": [
"category lifestyle"
],
"tie_post_head": [
"none"
],
"tie_post_slider": [
"59602"
],
"tie_googlemap_url": [
""
],
"tie_video_url": [
""
],
"tie_video_self": [
""
],
"tie_embed_code": [
""
],
"tie_audio_m4a": [
""
],
"tie_audio_mp3": [
""
],
"tie_audio_oga": [
""
],
"tie_audio_soundcloud": [
""
],
"tie_banner_above": [
""
],
"tie_banner_below": [
""
],
"tie_posts_num": [
""
],
"post_color": [
""
],
"post_background": [
"anything appropriate"
],
"tie_views": [
"2"
]
},
"thumbnail_size": "thumbnail",
"thumbnail_images": {
"full": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"thumbnail": {
"url": "anything appropriate",
"width": 150,
"height": 147
},
"medium": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"large": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"tie-small": {
"url": "anything appropriate",
"width": 55,
"height": 55
},
"tie-medium": {
"url": "anything appropriate",
"width": 272,
"height": 125
},
"tie-large": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"slider": {
"url": "anything appropriate",
"width": 290,
"height": 147
},
"big-slider": {
"url": "anything appropriate",
"width": 290,
"height": 147
}
}
},
{
//This is another "posts" object
}
]
}
I am not very familiar with javascript. So it's giving me real pain to push new fetched posts appending into the same "posts" array.
I can save the "posts" array into a variable into my app. But can't append new fetched objects after the last posts objects into the "posts" array.
obj.posts.push( { OBJ })basically.pushto thepostarray inside your object.