">Check out the new tutorial of version 1.7 +
In this tutorial we will see how to create a new post type for a list of music albums. We're going to create three new fields for album author, release year, and poster.
Click on the ADMIN FORM plugin and then on the "CREATE NEW FORM" button. As name we write Music and click on "Choose an existing table". Select wp_post and click save.
Once the list has been saved you will be redirected to the TAB FORM
We order the fields by dragging them from the two triangles on the blue titles. We put ID, post_title, post_content, post_status and post_type in the first positions. We set all the other fields to HIDE.
Click on the pencil next to post_title and set the field type: text (single line). We modify post_content and on the field type we choose Classic text editor.
On post_status we set the default value "publish" and select HIDE next to the title.
On post_type set as default value "music" and select HIDE next to the title.
Go to the bottom of the form and click on the ADD METADATA
button
Let's configure two new fields:
fieldname: artist
field Type: Text (single line)
field label: Artist
required
fieldname: cover
fieldType: Mediagallery
field label: Cover
Save the form
Now we have to tell our module that it should filter the data only for the post_type music.
Let's scroll down to the filters and choose pos.post_type as the field, = (Equals) as the operator and music as the value.
Let's save.
Warning the filters are not applied in the "Browse the list" tab!. To test it, go to the "music" menu item that will appear under the Admin Form.
This is the final result that should appear in the backend
Let's create a new wordpress page and insert the shortcode of the list that we find at the top right of each configuration page
Now let's go back to the plugin and on the List view formatting tab we modify the title to create the link to the single page of the post type.
Next to post_title click the pencil to edit the column and then deselect " Keeps settings aligned with information from the same field in tab 'Form'".
On Column Type I choose Custom and insert the following code:
<a href="[^LINK id=[%data.ID]]">[%data.post_title]</a>
We save
To make a new post type work, you must first register it, and then modify the content of the single page in order to view the added data. We can do everything inside the function.php file that we find inside the active template. At the bottom of the file we add
// Register post_type music
function adfo_type_music() {
$args = array(
'public' => true,
'query_var' => true,
'rewrite' => array('slug' => 'music')
);
register_post_type('music', $args);
}
add_action('init', 'adfo_type_music');
// I add metadata to the content
function adfo_single_page_music ( $content ) {
if ( is_single() && get_post_type() == "music") {
$adfo_detail = admin_form\ADFO::get_detail(8, get_the_ID(), false);
return $content . '<p>ARTIST: '.$adfo_detail->artist.'</p><p>Cover: '.$adfo_detail->cover.'</p>';
}
return $content;
}
add_filter( 'the_content', 'adfo_single_page_music');
Let's save the file. The last step that we must carry out in order to make the changes active we have to make wordpress regenerate the links. We can do it with a little trick. We go to administration in settings > permalinks and save the configuration without changing anything. This way wordpress will recalculate the site links and add our post type music.
We're done, now we can go to the music album list page. By clicking on the title you will go to the page with the detail of the article and at the bottom you will find the artist and the image of the album cover that you have entered.