<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Enrique Moreno Tent</title>
    <description>The latest articles on DEV Community by Enrique Moreno Tent (@enriquemorenotent).</description>
    <link>https://dev.to/enriquemorenotent</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F31301%2F07cd950f-c6a8-42d7-930b-61add0bdc628.jpeg</url>
      <title>DEV Community: Enrique Moreno Tent</title>
      <link>https://dev.to/enriquemorenotent</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/enriquemorenotent"/>
    <language>en</language>
    <item>
      <title>Creating custom post types in Wordpress</title>
      <dc:creator>Enrique Moreno Tent</dc:creator>
      <pubDate>Wed, 15 Aug 2018 00:00:00 +0000</pubDate>
      <link>https://dev.to/enriquemorenotent/creating-custom-post-types-in-wordpress-35fk</link>
      <guid>https://dev.to/enriquemorenotent/creating-custom-post-types-in-wordpress-35fk</guid>
      <description>&lt;p&gt;It is not seldom that a website needs different kinds of data. Wordpress comes out of the box with “post” and “page”, but we might need more.&lt;/p&gt;

&lt;p&gt;Many times this is achieved with &lt;strong&gt;categories&lt;/strong&gt; since they provide a way of differentiate between the content of the post, in relation with their content.&lt;/p&gt;

&lt;p&gt;But what happens if we start adding different data structures to our post? Let’s say that we want to define “city profiles” into out Wordpress system. A city might come with very different custom fields. For instance, &lt;code&gt;location&lt;/code&gt;, &lt;code&gt;amount of population&lt;/code&gt;, &lt;code&gt;continent&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The topic of how to add custom fields is in itself worth of another post, but let’s say that we have that as a given. We could separate the posts that represent a city within a “City” category, but that makes the management of data quite hard. One would have to look through all the posts for the needed data every time, and set the filters properly to reach the post one is looking for.&lt;/p&gt;

&lt;p&gt;There is a better way.&lt;/p&gt;

&lt;p&gt;First let’s register a new kind of post type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

// functions.php

add_action('init', 'register_custom_posts_init');

function register_custom_posts_init() {

    $cities_labels = array(
        'name' =&amp;gt; 'Cities',
        'singular_name' =&amp;gt; 'City',
        'menu_name' =&amp;gt; 'Cities'
    );

    $cities_args = array(
        'labels' =&amp;gt; $cities_labels,
        'public' =&amp;gt; true,
        'capability_type' =&amp;gt; 'post',
        'has_archive' =&amp;gt; true,
        'supports' =&amp;gt; ['title', 'editor']
    );

    register_post_type('city', $cities_args);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way we create an structure “City” that will contain all the information. If we look now in the Wordpress backend, we will see that a new menu item has been added, called “Cities”. There, we can add all the entries that belong within that data structure, without being disturbed by other kinds of post, and without worrying to set any other kind of flag to set our new data entry.&lt;/p&gt;

&lt;p&gt;Now, to query the information, we can do it this way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

$query = new WP_Query([
    'post_type' =&amp;gt; 'city',
    'order' =&amp;gt; 'ASC',
    'posts_per_page' =&amp;gt; 100
]);

$cities = $query-&amp;gt;posts;
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can query directly by post type, which is a very easy query to write.&lt;/p&gt;

&lt;p&gt;How about declaring a “Detail view” of our new post type? Usually for normal posts, we would be using a file &lt;code&gt;single.php&lt;/code&gt; but since we are using custom post types, we have to declare a file called &lt;code&gt;single-city.php&lt;/code&gt;. It is inside this file where we will be displaying the information in detail of one entry.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTICE!&lt;/strong&gt; One important thing to remember. After creating your new post types, it would be a good idea to go to &lt;code&gt;Settings &amp;gt; Permalinks&lt;/code&gt; and update the settings there. The configuration might need a flush to recognize the new post type. An error that happened to me too often.&lt;/p&gt;

&lt;p&gt;This is a new way of representing data that I will not be forgetting anytime soon, when it comes to Wordpress development.&lt;/p&gt;

&lt;p&gt;Cheers&lt;/p&gt;

</description>
      <category>wordpress</category>
    </item>
    <item>
      <title>Different notations used for compound words</title>
      <dc:creator>Enrique Moreno Tent</dc:creator>
      <pubDate>Wed, 01 Aug 2018 00:00:00 +0000</pubDate>
      <link>https://dev.to/enriquemorenotent/different-notations-used-for-compound-words-1d2j</link>
      <guid>https://dev.to/enriquemorenotent/different-notations-used-for-compound-words-1d2j</guid>
      <description>&lt;p&gt;Programmers usually have a problem when they have to use more than one word to describe something, but they are not allowed to use spaces or punctuation signs. An example of this would be to name files. If someone wants, for instance, to name a picture where 2 people are talking, he would like to write &lt;code&gt;John and Mike talking.jpg&lt;/code&gt;, but since a filename cannot contain spaces, he may write something like &lt;code&gt;john-and-mike-talking.jpg&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To do this, there are many popular conventions, even though they are not standarized. Let’s take a look at some of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Camel case
&lt;/h2&gt;

&lt;p&gt;This system consists in writing compound words or phrases such that each word in the middle of the phrase begins with a capital letter.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;suchWonderfulBlog.txt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;leaveCommentsBelow.pdf&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Pascal case
&lt;/h2&gt;

&lt;p&gt;This is a variation from camel case notation. The only difference is that the first letter of the first word is also capitalized. Also called &lt;code&gt;upper camel case&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;SuchWonderfulBlog.txt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;LeaveCommentsBelow.pdf&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Snake case
&lt;/h2&gt;

&lt;p&gt;In this notation each word will be joined together with a unique underscore.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;such_wonderful_blog.txt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;leave_comments_below.pdf&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Kebab case
&lt;/h2&gt;

&lt;p&gt;This case is similar to snake case, but instead of using an underscore, an hyphen is used to join words together.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;such-wonderful-blog.txt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;leave-comments-below.pdf&lt;/code&gt;&lt;/p&gt;




&lt;p&gt;Let me know if I have missed something!&lt;/p&gt;

</description>
      <category>notation</category>
    </item>
  </channel>
</rss>
