Need to get the 'GUID' value for WordPress plugin - wordpress

I have developed a plugin for creating automatic page which containing the following code:
$new_page = array(
'slug' => $_REQUEST[sl_store],
'title' => $_REQUEST[sl_store],
'content' => "$_REQUEST[sl_store] <br> $_REQUEST[sl_address]"
);
$new_page_id = wp_insert_post( array(
'post_title' => $new_page['title'],
'post_type' => 'page',
'post_name' => $new_page['slug'],
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_content' => $new_page['content'],
'post_status' => 'publish',
'post_author' => 1
));
The page is creating fine. However, I need to fetch the "GUID" value for the newly created page from the DB.
Can anyone help me?

There's a get_the_giud() function (see here). So
get_the_guid( $new_page_id );
should do what you need.

Related

Adding a taxonomy term to acf_form()

I am using the acf_form() function from Advanced Custom Fields to allow users to create posts through a front end form on my WordPress site.
What I can’t get my head around is how to add a taxonomy term from a custom taxonomy to those posts when they are created.
Here is the code I have so far which is working well to create the post.
acf_form(array(
'post_id' => $submission_id,
'post_title' => true,
'post_content' => false,
'new_post' => array(
'post_type' => '2017-submission',
'post_status' => 'publish',
),
'submit_value' => __("Save", 'acf'),
));
And here something similar to what I would expect to work. Lines 8 and 9 are made up.
acf_form(array(
'post_id' => $submission_id,
'post_title' => true,
'post_content' => false,
'new_post' => array(
'post_type' => '2017-submission',
'post_status' => 'publish',
'key' => 'project-category', // This is made up and does not work
'value' => 'housing', // This is made up and does not work
),
'submit_value' => __("Save", 'acf'),
));

Wordpress - "Unknown post type" when editing

I wrote a script to add new entries into my "interactions" post type, but they don't come up in interactions, and when I manually point my browser to the ID of the post in the editor, it tells me "Unknown post type".
Heres the code I added the post with:
$new_post = array(
'post_title' => $title,
'post_content' => '',
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => '',
'post_type' => 'interaction'
);
$id = wp_insert_post($new_post);``
The post is being created but the new entries don't show up on the interactions list and I can't edit it because it tells me its an unknown post type.
What could be causing this issue?
You have an typo in your post_type parameter. Change it to: interactions instead of interaction
<?php
$new_post = array(
'post_title' => $title,
'post_content' => '',
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => '',
'post_type' => 'interactions'
);
$id = wp_insert_post($new_post);

Set sidebar position disabled and hide page title through php wordpress plugin

I've created a plugin for wordpress that can auto post pages on demand
my problem is formatting this pages to a specific template
I need that when the post page is auto inserted in the DB, set the Sidebar position to disabled in order to have a full width page and hide the page title... this options appear in the dashboard and I can click on them one by one, but that has to be automatic, not manually.
$my_post = array(
'post_title' => wp_strip_all_tags( $tituloFichaP1 ),
'post_content' => $content,
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array( 8,39 ),
'post_type' => 'page',
'post_parent' => $parentPost,
'page_template' => 'microsite',
'comment_status' => 'open',
);
wp_insert_post( $my_post );
By the way, the page_template attribute ('page_template' => 'microsite') doesn't work either. Te post is inserted but the template is set to default.
Thanks in advance!!!
I just go through you code, you have done a simple mistake, in "page_template" that should be a file name (filename.php) of your template not a template name . for ex. if your template microsite's file name is microsite.php than your code will be.
$my_post = array(
'post_title' => wp_strip_all_tags( $tituloFichaP1 ),
'post_content' => $content,
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array( 8,39 ),
'post_type' => 'page',
'post_parent' => $parentPost,
'page_template' => 'microsite.php',
'comment_status' => 'open',
);
wp_insert_post( $my_post );
Hope this will help you.

Create a filter in a page template

I am using Realto theme for wordpress I am wondering if I am on the correct path. I need to display properties from a city. So I decide to create a page template to add the location
This are the default arguments but I dont know how to filter the results by city
$args = array(
'numberposts' => '',
'posts_per_page' => $posts_per_page,
'offset' => 0,
'cat' => '',
'orderby' => 'date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'property',
'post_mime_type' => '',
'post_parent' => '',
'paged' => $paged,
'post_status' => 'publish'
);
I tried adding
'locations' => 'MYCITY'
but it didnt work
This is an example of the search results when I search by city, so I am basing my arguments on this.
/?post_type=property&search_keyword=&locations=MYCITY&property_type=proyectos&beds=&baths=&status=&min-price=&max-price=
I assume that locations is a custom field? Maybe this works:
<?php
$args = array(
'post_type' => 'property',
'meta_key' => 'locations',
'meta_value' => 'MYCITY'
);
?>
Visit http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters for more details.

Create a new page with wp_insert_post ()

I have the following code in a PHP function that is activated when I install my plugin that lets you create a post or page.
Works perfect and make the page if the $post_type is "post", but if the $post_type is "page", then it does not work, does not create the page.:
$my_post = array(
'post_title' => 'My page Reql',
'post_type' => 'page',
'post_name' => 'my-page',
'post_content' => 'This is my page reql.',
'post_status' => 'publish',
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_author' => 1,
'menu_order' => 0
);
wp_insert_post( $my_post );
What is the problem? I can not find the solution.
Thank you very much!
I think you have to set the guid too, like this
$PageGuid = site_url() . "/my-page-req1";
$my_post = array( 'post_title' => 'My page Reql',
'post_type' => 'page',
'post_name' => 'my-page',
'post_content' => 'This is my page reql.',
'post_status' => 'publish',
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_author' => 1,
'menu_order' => 0,
'guid' => $PageGuid );
$PageID = wp_insert_post( $my_post, FALSE ); // Get Post ID - FALSE to return 0 instead of wp_error.

Resources