ACF Form Post not showing on frontend straight away - wordpress

I am using ACF's front end editor capabilities to enable my users to upload a post to the site.
The user fills out the form and submits and the data shows correctly in the backend. The issue I'm facing is the homepage (which shows all the latest posts) has to be refreshed in order to show the post that has just been uploaded.
Is there a way this can populate straight away? The idea is once the user has filled out the front end form, they are taken to the post they have just created (which works fine). If they then click onto the homepage, they should be able to see the post title there without having to refresh the page.
My form code is:
<?php acf_form(array(
'post_id' => 'new_post',
'field_groups' => array(152),
'new_post' => array (
'post_status' => 'publish',
),
'post_title' => true,
'submit_value' => 'Submit',
'return' => '%post_url%'
)); ?>

This was fixed by adding
?loggedin=true
to the end of the URL when the user logs in and gets redirected to their profile.

Related

Code star framework add metabox to a specific page

I am using the code star framework full version. I have integrated the framework with the theme. How can I show the meta box option only for some specific pages ( like home page and about page )? Currently, the meta box options are showing all pages.
While creating metabox, you should pass "page_templates" value in array. For example, if you want to show metabox on homepage you should do:
$homePage = 'home-page';
CSF::createMetabox($homePage, array(
'title' => 'Homepage',
'post_type' => 'page',
'page_templates' => 'index.php', //filename goes here
'data_type' => 'serialize',
));
For more info: http://codestarframework.com/documentation/#/configurations?id=metabox-option-framework

Creating pages from Ninja form data

I've created a WordPress page with a Ninja form on it that collects miscellaneous data about a product, including some uploaded images. The page with the form is accessible from the main menu by clicking the "Input" item, so the user doesn't need to access the backend to upload their product data.
I now want to put this data into a custom post type called "Listing." There will eventually be thousands of these data sets and so thousands of "Listing" pages, as people come to the site, click Input in the main menu to get to the page with the Ninja form and fill it out.
Could someone tell me how they would go about now building these listing pages from the data the form has collected?
I'm running Ninja's Front-End Post option which supposedly will create a page from the form data. This plugin has some Post creation settings where you can select the post type to create, but this isn't working for me. I would expect the submitted form data to show up under dashboard | Listings, but there's nothing there after submitting the form.
Has anyone gotten this to work?
Thanks for your help.
I think you can use only Ninja Forms without extensions, and hook directly in 'ninja_forms_after_submission' that fires after submission and allow you to use data submitted and perform actions.
This is a starter codebase to achieve your result, but needs to be customized on your needs and your form structure.
add_action( 'ninja_forms_after_submission', 'create_page_from_ninjaform' );
function create_page_from_ninjaform( $form_data ){
// your fields data
$form_fields = $form_data[ 'fields' ];
// !!! this is an example, it depends form fields in your form
$title = $form_fields[ 1 ][ 'value' ];
$content = $form_fields[ 2 ][ 'value' ];
$sample_meta_field = $form_fields[ 3 ][ 'value' ];
$new_post = array(
'post_title' => $title,
'post_content' => $content,
'post_status' => 'publish',
'post_type' => 'listing', // be sure this is the post type name
);
$new_post_id = wp_insert_post( $new_post );
update_post_meta( $new_post_id, 'your_meta_key', $sample_meta_field );
}
This code should be copied in functions.php file
Not tested of course.
Good luck ;)
The Ninja Forms Front-end Posting extension isn't really meant for displaying form submission data on the front end.
From: https://ninjaforms.com/extensions/front-end-posting/
"The Ninja Forms Front-end Posting extension gives you the power of the WordPress post editor on any publicly viewable page you choose."
If you want to show Ninja Forms submission data on the front end, you will have to retrieve them from the database with code in functions.php or by writing a plugin (recommended). You could then parse and manipulate them and create a shortcode that would allow you to insert your formatted submission data easily in Wordpress posts or pages.
Here's a link to a feature request, asking for the same thing. The author of that request posted a link to a plugin (click Download as Plugin) they wrote which may do what you want or give you further insights as to how you could implement this.
https://github.com/wpninjas/ninja-forms/issues/892
If you do not mind paying a little money for a plugin I would recommend using gravity forms rather then ninja forms for more advanced stuff like this.
I manually create a custom post type "oproep" and used a gravityforms plugin to create a custom post from type oproep when an user submits the form.
Because you use custom post type archive pages www.mysite.com/oproep will be automatically created so you already have a list of "Listings". The singe pages www.mysite.com/oproep/title will also be created for you by default, you could override these templates as well if you would like depending on your theme.
The only thing you have to do is add a few php lines to your functions.php (or write your own plugin) that adds the custom post type. The rest all works automatically.
I went so far as writing code to make users able to edit their submissions, read custom taxonomy tags in dropdowns etc. You got lots and lots of more options using gravity forms.
FrancescoCarlucci's answer is correct, but just adding an additional comment: in case you want to specify by form field IDs which fields should go where in your post, NinjaForms passes the ID as a number (in my case for example, I needed field 136 for my post title). It may have been obvious but I racked my brain for a while until I figured it out.
function create_post($form_data) {
$form_fields = $form_data[ 'fields' ];
$post_fields = array(
'post_content' => '',
'post_content_filtered' => '',
'post_title' => '',
'post_excerpt' => '',
'post_status' => 'pending',
'post_type' => 'post',
);
foreach ($form_fields as $field) {
$field_id = $field[ 'id' ];
$field_key = $field[ 'key' ];
$field_value = $field[ 'value' ];
if ($field_id == 136) {
$post_fields['post_title'] = $field_value;
}
}
wp_insert_post($post_fields, true);
}

Show Multiple Post Thumbnails only in one page

I use Multiple Post Thumbnails plugin to add many thumbnails to my page.
for($i=1; $i<=10;$i++){
new MultiPostThumbnails(
array(
'label' => 'Photo - '.$i,
'id' => 'Photo-'.$i,
'post_type' => 'page'
)
);
}
But I need to have them only in one of the pages, not all. Now if I open any pages in admin, I see 10 Post Thumbnails fields. I need to specify the ID on the page and see them only in that page in admin.

Creating a delete confirmation for images using the Wordpress meta box plugin

I am using the Meta Box plugin for Wordpress. I can successfully create fields in the cms for users to upload images. I would like to extend this in two ways:
First, I would like a delete confirmation when users remove an image from the image gallery
Here is the code:
$meta_boxes[] = array(
'id' => 'project_media',
'title' => 'Project Media',
'pages' => array( 'project' ),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'name' => 'Media Gallery',
'desc' => 'Images should be sized to 983px x 661px',
'id' => $prefix . 'project_media_gallery',
'type' => 'image'
)
);
This creates upload functionality in the custom post type where users can add images to a slideshow. The problem is if the user accidentally clicks the delete button, there is no confirmation to make sure it is deleted. Can I somehow extend the plugin through functions and call an alert when this button is clicked? Something that does not involve editing the WP core?
Second, the base functionality requires the user to upload an image from their local machine. Is there a way to tap into the Media Library for this?
No idea how to even start tackling this one.
To answer the first question
First, I would like a delete confirmation when users remove an image from the image gallery
You can do that by calling a custom script file from the functions.php.
function alert_delete() {
if(is_admin()){
wp_register_script( 'alert_delete', get_bloginfo('template_url'). '/js/alert_delete.js', array('jquery'));
wp_enqueue_script('alert_delete');
}
}
and create a file named alert_delete.js in the js directory of your theme.
alert_delete.js:
// admin delete check
jQuery(document).ready(function(){
jQuery(".rwmb-delete-file").click(function() {
if (!confirm("Are you sure? This process cannot be undone.")){
return false;
}
});
});
In response to the second question...
Second, the base functionality requires the user to upload an image
from their local machine. Is there a way to tap into the Media Library
for this?
Get the latest version of the Meta Box Plugin first.
then change
'type' => 'image'
to
'type' => 'image_advanced'
which will allow you to upload from the existing Media Gallery or a new file from your computer.

Dynamically maintain virtual pages URL without create pages from admin

I created a page named UserName its URL is http://my_site/username/. On this page I am showing three links, and each link behaves as meta info for UserName.
Let's suppose:
If UserName contains info about User then the three links are:
About Me
Images
Videos
and links contains href like:
http://my_site/username/about_me
http://my_site/username/images
http://my_site/username/videos
now I create three general files like:
about_me.php
images.php
videos.php
and want to include these file by checking the URL, but I don't know how.
I did it without adding new page from wp-admin because there will be so many UserName pages but they all have same three links and will show the info about respective user.
And if I prefer to create About Me child page whose parent will be the UserName page then admin will need to create 3*(n UserName) pages where n least value is 100 and could be 1000s
But when I click any link WP says
Page Not Found
This is somewhat embarrassing, isn’t it?
I select Custom Structure from Settings and I have no more idea about WP permalinks.
You may call I need to create Virtual pages for all users.
If it is not possible then is it possible that while adding new UserName page then on published three pages (About Me, Images & Videos) will automatically with parent page newly UserName page and with a defined Page Template. If it is possible then how?
Wow I got an idea, implement & hurray it worked.
In wp-admin/includes/post.php I add my script in function edit_post( $post_data = null )
First I checked if post not already exists then run my script which is:
$post = array(
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_author' => $current_user_id,
'post_date' => date('Y-m-d H:i:s'),
'post_date_gmt' => date('Y-m-d H:i:s'),
'post_name' => 'Image',
'post_parent' => $post_parent,
'post_status' => 'publish',
'post_title' => 'Image',
'post_type' => 'page'
);
// Insert in to WP wp_posts table
$this_post_id = wp_insert_post( $post, $wp_error );
// Insert in to wp_postmeta table
$meta_id = update_post_meta($this_post_id , '_wp_page_template', 'page-three-columns.php');

Resources