Multiple Authors on same post in Wordpress - wordpress

I have a friend who has asked me to build a site for him and two friends to write movie reviews. I'm pretty good with Wordpress, so it was the obvious choice for the site. The only difficulty I have is that they each plan to write a review on the same movie, and I can't think of how to achieve multiple authors in one post.
I've checked out a few plugins such as Co-Author Plus which allows multiple authors credited to the same post, but it doesn't provide the functionality for keeping each author's content separate.
The only solution I can think of is to use custom fields, but I would prefer if the authors can use the main content editor for their reviews. Any help is greatly appreciated!

Like I said, it should be better to have 1 review = 1 post.
So, I think the best way to achieve this should be to create post types :
movie
review, with a movie reference field
And modify post template to display movie and associated reviews on the same page.
An alternate solution should be to use taxonomy to handle movies and attach post to them.

I ran into the same problem with trying to figure out how to do this as well and I followed soju's advice and came up with a solution. There might be a better solution to this, but this is how I went about it. Me and my friend are doing an anime review blog and both me and him will be writing a review on the same anime.
I first created two post types:
anime: main page on the specific anime, like the description, pictures, etc.
reviews: the author's review on the anime. the options i have enabled on here are the editor, the title, and the author. Along with the associated anime taxonomy. That's all that's needed here
Then I created a taxonomy for anime titles so when a user needs to write a review on an anime that hasn't been added as a review yet they can add the title into the taxonomy.
I associated the taxonomy to both post_types and wala! That's pretty much all you need.
So now when you want to write a new review for a new anime you add a anime post type first and write down what the anime is about and include pictures etc. Add the title to the taxonomy and check it. After that you then create a new post of the post type reviews and write your review, remember to check the correct title in your taxonomy for what anime this is going to, then you are ready to go!
Problem 1: How do I include this into my loop?
Well you don't want to include both post types in your loop you just want to include posts and the other post type anime in your loop so you do the following in your functions.php file:
function include_custom_post_types( $query ) {
global $wp_query;
// Get all custom post types
$custom_post_type = get_query_var( 'post_type' );
// Get all post types
$post_types = get_post_types();
// If what you are getting is a category or a tag or that there are no custom
// post types you just want to set the post types to be the current post types
if ( (is_category() || is_tag()) && empty( $custom_post_type ))
$query->set( 'post_type' , $post_types );
// Set the custom post types you want to ignore
$ignore_types = array('reviews');
//Unset the post types that are gonna be ignored
foreach($post_types as $key=>$type)
{
if(in_array($type,$ignore_types))
{
unset($post_types[$key]);
}
}
// Set the post types for the query
if ( (is_home() && false == $query->query_vars['suppress_filters']) || is_feed())
$query->set( 'post_type', $post_types);
return $query;
}
add_filter( 'pre_get_posts' , 'include_custom_post_types' );
Problem 2: How do I display the reviews?
I solved this by creating another single.php file and renamed it to single-post_type_name.php. So in this case i created a single-anime.php file for my post type anime. Then in place of the contents i want to get all the reviews for this specific anime so I added the following within the file in the main content area:
<?php
//You grab the taxonomy that you have selected for this post
$terms = wp_get_post_terms(get_the_ID(), 'animes_reviewed');
// This is the args array for the criteria that the posts need to be in
$args = array(
// This is the post type of where your reviews are at
post_type' => 'reviews',
// this is for searching the taxonomy usually it's
// taxonomy_name => checked_taxonomy
'anime' => $terms[0]->name,
'post_status' => 'publish'
);
// Grab the posts
$posts = get_posts($args);
//Here I echo out the information for debugging purpose, but
//Here is where you can do HTML to display your reviews
foreach($posts as $post)
{
echo($post->post_content);
the_author_meta( 'nickname', $post->post_author);
}
?>
You can do a lot more with this adding more taxonomies etc. I have actually implemented an episode review by just adding a taxonomy and adding a criteria to look for in the post section. Hopefully this will help you out, might be a bit late though :( Thanks soju for recommending the custom post types!

Related

Wordpress ACF how to display something other than post title for custom relationship field in Admin

I have custom post types for which having a 'title' field doesn't really make sense, so the post type has none.
Problem is that when you use a post type in a relationship, the user interface for picking which posts to relate wants to display the title.
In the box where you are choosing posts (clicking them and they move to the right pane), can a field other that 'title' be displayed?
It's doable. I would use a filter hook provided by acf plugin 'acf/fields/relationship/result/name=related_posts'. Take a look at the following code:
add_filter( 'acf/fields/relationship/result/name=related_posts', 'my_custom_title', 10, 2 );
function my_custom_title( $title, $acf_array ) {
// You could remove the $title altogether or you could add something meaningful to it such as time stamp or anything that would make sense!
return $title . "Adding somthing meaningful to the title!";
}

Get the parent taxonomy for custom post type

I have a custom post type called 'listing' and a custom taxonomy called 'listing-category'
I am trying to create a class for the single-listing.php posts that is the slug of the parent custom taxonomy only eg:
STAY
- Hotel
- B&B
EAT
- Cafes
- Bakery
SHOP
- Food
- Shoes
So for single posts under hotel - I need to create a class of 'stay' as all posts under that class will have the same style.
What I hope to output is for example:
<div id="main-content" class="stay">
This previous question seems closest but I can't seem to get it working for my project: https://wordpress.stackexchange.com/questions/24794/get-the-the-top-level-parent-of-a-custom-taxonomy-term
I've been going around in circles for about two days with this so any help would be really appreciated!
Actually that answer you have given the link to is OK and solves your problem as well. May be you do wrong implementation.
Here is sample code for your case:
global $post;
$ctp_listing_cats=wp_get_post_terms( $post->ID, 'listing-category' );
if (!empty($ctp_listing_cats[0]->term_id)){
$topparent=get_term_top_most_parent($ctp_listing_cats[0]->term_id,'listing-category');
}
//...
echo '<div id="main-content" class="'.$topparent->name.'">';
get_term_top_most_parent() function of the given code is the function from another answer you gave link to.
It would be better to add one more parameter to wp_get_post_terms,
When you set 'parent' => 0 and it return only parents.
For example:
$company_locations = wp_get_post_terms( $car_id, 'location', array('parent' => 0) );

Add specific words to WordPress custom type slug

I have a WordPress installation with a custom type (places) wich produces this permalink structure:
http://example.com/places/the-first-site/
And I would like to show all my sites like this:
http://example.com/places/visit-the-first-site-and-enjoy/
where 'visit' and 'and-enjoy' would be always those specific words (constants).
Even better I would like to put a custom taxonomy I have (year) as a metadata
places/visit-the-first-site-and-enjoy-1985/
I can access the DB and modify the post name of all post, but I would have to do for the new post also, and I'm looking for some automated rule, but can't find how to do.
Maybe some rewrite rule, but I don't know how to do it.
Any ideas??
You do not have to edit anything in your database nor any codes in your WordPress installation; you can achieve that directly from your WordPress administration panel.
From your Dashboard, click on the Permalink sub-menu under Settings; there, you will have to select the Custom Structure option and set it as follow in order to achieve your desired effect:
/places/visit-%postname%-and-enjoy-%year%/
Please note: here, we made use of both %postname% and %year% Structure Tags so as to get names of posts with their corresponding year of publication respectively.
Don't forget to click on the Save Changes button on the page in order to effect your changes.
... Read more on Permaklinks (for general knowledge).
For a custom post type and taxonomies as expressed further in comments, you will need a custom solution which will require a little bit of coding and or tweaking, depending on your abilities; you may use this handy plugin (Custom Post Type Permalinks) from the WordPress.org Plugins repository.
This posts should equally be of great help to you, to getting started and understanding further, should you chose to code.
You have différent hook like save_post or pending_to_publish, where you can set or change the "post_name" (that's corresponds to the permalink slug).
To Add specific words to WordPress custom type slug You have to Register custom rewrite rules.
suppose this is Your URL http://example.com/places/the-first-site !
and you have a post type places.
function add_rewrite_rules()
{
$wp_rewrite->add_rewrite_tag('%places%', '([^/]+)', 'places=');
$wp_rewrite->add_rewrite_tag('%state%', '([^/]+)', 'state=');
$wp_rewrite->add_permastruct('places', 'places/visit-%state%-and-enjoy/', false);
}
function permalinks($permalink, $post, $leavename)
{
$no_data = 'no-data';
$post_id = $post->ID;
if($post->post_type != 'story' || empty($permalink) || in_array($post->post_status, array('draft', 'pending', 'auto-draft')))
return $permalink;
$state = get_post_meta($post_id, 'location', true);
if(!$state)
$state = $no_data;
$permalink = str_replace('%state%', $state, $permalink);
return $permalink;
}
add_action('init', 'add_rewrite_rules');
add_filter('post_type_link', 'permalinks', 10, 3);
put this code in your custom post type plugin. and if get page not found error please change your permalink setting. or make a custom template file to show this post.

Custom post status not appearing

I am building a directory theme for a client of mine, and I like to add the feature of expiration in the posts by modifying the post status from publish to expired.
To achieve that, I am trying to register a new post status by using the following code:
add_action('init', 'registerStatus', 0);
function registerStatus()
{
$args = array(
'label' => _x('Expired', 'Status General Name', 'z' ),
'label_count' => _n_noop('Expired (%s)', 'Expired (%s)', 'z'),
'public' => true,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'exclude_from_search' => true
);
register_post_status('expired', $args);
}
The problem is that I cannot see the registered post status either in WordPress posts, either in my custom post type post statuses.
Am I doing something wrong?
Thanks to Ryan Bayne I was able to add a custom post status to the admin panel on the edit post page. There is no wordpress filter avaiable. His solution with jQuery is perfect. Here the code if anyone else is searching for a solution:
add_action( 'post_submitbox_misc_actions', 'my_post_submitbox_misc_actions' );
function my_post_submitbox_misc_actions(){
global $post;
//only when editing a post
if( $post->post_type == 'post' ){
// custom post status: approved
$complete = '';
$label = '';
if( $post->post_status == 'approved' ){
$complete = 'selected=\"selected\"';
$label = '<span id=\"post-status-display\"> Approved</span>';
}
echo '<script>'.
'jQuery(document).ready(function($){'.
'$("select#post_status").append('.
'"<option value=\"approved\" '.$complete.'>'.
'Approved'.
'</option>"'.
');'.
'$(".misc-pub-section label").append("'.$label.'");'.
'});'.
'</script>';
}
}
Custom post status functionality is still under development (as it has been for the past four years!), see https://core.trac.wordpress.org/ticket/12706, and comments on https://wordpress.stackexchange.com/q/67655/25765. More useful info here: https://wordpress.stackexchange.com/search?q=register_post_status.
Personally, I'd strongly discourage implementing custom post statuses, but if really necessary, you could take a look at how the Edit Flow plugin handles it.
This feature is still pending for future development
NOTICE:
This function does NOT add the registered post status to the admin panel. This functionality is pending future development. Please refer to Trac Ticket #12706. Consider the action hook post_submitbox_misc_actions for adding this parameter.
Now November 2014 and still issues with custom statuses. I think the original code posted is fine. Here is a video showing an issue you will run into when implementing custom post status though. There may be a workaround i.e. hooking into the posts query and doing a custom query but I've not started the research.
Screencast of posts not showing in the All table when a custom status is applied, however the posts can be found in the table view for each custom status. Click here to view short clip.
That screencast was taking while I worked on my new WTG Tasks Manager plugin. I will leave my design in the plugin as it is and hopefully it helps to encourage improvements in this area of WordPress.
For proper answer...my custom status do show on the Edit Post screen for my custom post type so that is possible. If you want to take a look at my plugins registration of custom post type and statuses go to directory "posttypes/tasks.php" and play around with a working example. Here is the plugins official page...
https://wordpress.org/plugins/wtg-tasks-manager/

Wordpress; Vantage theme & ACF plugin?

I have repeatedly been trying to implement the Advanced Custom Fields (ACF) plugin in the Vantage theme (from AppThemes), but without any success. I've had extensive contact with the admin of ACF, on this subject, but unfortunately we did not succeed. He advised to ask here, maybe seek for a (paid) developer, to solve this problem.
Ok, so what am i trying?
I have created a custom field group and want to implement that field group within the listing form of Vantage. To do so i have read several docs, including: http://www.advancedcustomfields.com/resources/tutorials/creating-a-front-end-form/. To be complete, based on this i did the following in the Vantage theme folder:
I created 2 custom field groups, with the id's: 88 & 139.
In Wrapper.php i added the code: <?php acf_form_head(); ?>
In form-listing.php i created 2 custom hooks, 'product_custom' and 'product_custom2': <?php do_action( 'product_custom' ); ?> <?php do_action( 'product_custom2' ); ?>
In fuctions.php i created 3 functions:
add_action( 'wp_print_styles' , 'my_deregister_styles' , 100 );
function my_deregister_styles() {
wp_deregister_style( 'wp-admin' );
}
add_action( 'product_custom' , 'productfields' );
function productfields() {
$options = array(
'field_groups' => array('post' => '88' ),
'form' => false,
);
acf_form( $options );
}
add_action( 'product_custom2' , 'productfields2' );
function productfields2() {
$options2 = array(
'field_groups' => array('post' => '139' ),
'form' => false,
);
acf_form( $options2 );
}
This actually made the custom field group show up in the listing form of Vantage. However the following things keep going wrong:
Both field groups have a WYSIWYG field. However for some reason the WYSIWYG buttons and media button stop working
I cannot fill in any text in the first WYSIWYG field. Only the second one works for that matter.
No data is stored at all after saving the listing form. On advise of the ACF admin, i tried the following in the acf-master/core/api.php file:
// run database save first
if( isset($_POST['acf_save']) )
{
$txt="Hello world!";
echo $txt;
die();
However the string does not display after saving the listing form. So the if statement is not used...
4. To display the dataon the frontend, once they are saved, I guess the default wordpress codex can be used..
I tried to be as complete as possible;) Is there anybody who can help me any further? Paid assistance is also negotiable..
Thanks a lot in advance!
Robbert
I have succeed on implementing ACF with vantage themes.
I add ACF form at vantage listing form and combine the vantage form with ACF form. with one button.
The data has been saved to database and can be called to displayed in listing area. Only add image button is not working from front-end but in back-end the button is working.
Adding <?php acf_form_head(); ?> to wrapper.php
Do this tutorial front end form help
Eliminate default vantage submit button in form-listing.php
Add this code in ACF api.php in function acf_form_head()
// allow for custom save
$post_id = apply_filters('acf_form_pre_save_post','va_after_create_listing_form', $post_id);
That's it, hope it work in your site.
Is that you want when someone visits the website that they are able to send info via the page they visits eg www.yoursite.com/listing/listing-name like probably an email or contact for more info relating to that business?
If not then you can simply add in the ACF data from the back-end i.e. dreamweaver etc onto single-listing.php and use the ACF tutorial on working with fields.
Hope this helps somewhat
Cheers

Resources