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');
Related
Is there a way to generate multiple new pages in wordpress with the same template, content and everything else except page name in Wordpress. The names of the new pages will be from a list of about 300 cities.
I found a plugin called BulkPress where i can insert the list and it generates the pages but with the default template and no content.
EDIT: Sorry i missed one important thing!
All the pages need to be subpages of one already made parent page and the template and content needs to be copied from that parent!
You could create this with programmatically. Put below code in your active template functions.php. It will insert 300 pages.
wp_insert_post( array $postarr, bool $wp_error = false, bool $fire_after_hooks = true )
e.g.,
foreach($i=1;$i<=300;$i++){
$my_post = array(
'post_title' => wp_strip_all_tags( "Your post Title" ),
'post_type' => 'page',
'post_content' => "Post Content Goes here",
'post_status' => 'publish',
'post_author' => 1,
'page_template' => 'template-blog.php',
'post_author' => get_user_by( 'id', 1 )->user_id,
);
// Insert the post into the database
wp_insert_post( $my_post );
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.
I'm currently in the process of building my own WordPress plugin.So i need to create a new page(or post) that will be automatically added to word press when the plugin is activated.And this will be removed when plugin is deactivated.Content in the page is what content i am typing in the plugin.
HOW CAN I DO THAT?
you can use wp_insert_post function to create page or post check this http://codex.wordpress.org/Function_Reference/wp_insert_post
ex.
// Create post object
$my_post = array(
'post_title' => 'My post',
'post_content' => 'This is my post.',
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(8,39)
);
// Insert the post into the database
$post_id = wp_insert_post( $my_post);
you can use $post_id withing add_post_meta or update_post_meta or use post_meta varible to install and uninstall the page.
Something like this? There's some code referenced in the linked post for dealing with page creation. There's also the codex.
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.
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.