Adding a taxonomy term to acf_form() - wordpress

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'),
));

Related

How to specify custom fields in WordPress "meta_query" (for serialized arrays)

I am creating my own function to duplicate a custom post type (sample_products).
There are several custom fields in the custom post.
I have a custom post type that has a custom field for "sample_meta_setting".
For some reason I cannot include "sample_meta_setting" when duplicating a custom post.
Is there a solution?
We will also send you a capture of the database structure just in case.
The source code is long, so I will omit the whole of it.
The following sections specify the target of replication.
(Original source: https://rudrastyh.com/wordpress/duplicate-post.html)
$args = array(
'comment_status' => $post->comment_status,
'ping_status' => $post->ping_status,
'post_author' => $new_post_author,
'post_content' => $post->post_content,
'post_excerpt' => $post->post_excerpt,
'post_name' => $post->post_name,
'post_parent' => $post->post_parent,
'post_password' => $post->post_password,
'post_status' => 'draft',
'post_title' => $post->post_title,
//'post_type' => $post->post_type,
// Specify custom fields for custom post types
'post_type' => 'sample_products',
'meta_query' => array(
array(
'key' => 'sample_meta_setting',
'value' => 'a:1:{i:0;s:3:"foo";}'
),
),
'to_ping' => $post->to_ping,
'menu_order' => $post->menu_order
);

Get Wordpress Tags With 0 Posts Count

I'm trying to get some tags from wordpress database, tags that aren't assigned to any posts, so their post count is 0.
The code i use selects only the tags with 1 or more posts assigned...
<?php
$args = array(
'smallest' => 12,
'largest' => 24,
'unit' => 'px',
'format' => 'flat',
'orderby' => 'name',
'order' => 'DESC',
'exclude' => null,
'include' => null,
'topic_count_text_callback' => 'default_topic_count_text',
'link' => 'view',
'taxonomy' => 'post_tag',
'echo' => true,
'child_of' => null,
'show_count' =>1
);
?>
How can i get the tags with 0 posts assigned to show?
Set hide_empty to false in the arguments of the get_tags function.
get_tags(array('hide_empty' => false));
If you're using custom taxonomy, use get_terms function.
get_terms('custom_tags', array('hide_empty' => false));

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);

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.

Need to get the 'GUID' value for WordPress plugin

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.

Resources