<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Query - Themespress</title>
	<atom:link href="https://themespress.ca/en/sujets/query/feed/" rel="self" type="application/rss+xml" />
	<link>https://themespress.ca/en/</link>
	<description>Des tutoriels et ressources WordPress</description>
	<lastBuildDate>Sat, 01 Oct 2022 18:43:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>

<image>
	<url>https://themespress.ca/wp-content/uploads/2020/10/cropped-Favicon-Themepress.ca_-32x32.png</url>
	<title>Query - Themespress</title>
	<link>https://themespress.ca/en/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Creating a Query Post Shortcode for WordPress</title>
		<link>https://themespress.ca/en/creating-query-post-shortcode/</link>
					<comments>https://themespress.ca/en/creating-query-post-shortcode/#respond</comments>
		
		<dc:creator><![CDATA[Daniel]]></dc:creator>
		<pubDate>Fri, 24 Jun 2022 18:25:53 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[Query]]></category>
		<guid isPermaLink="false">https://themespress.ca/?p=6294</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<div class="wpb-content-wrapper"><div class="vc_row wpb_row vc_row-fluid"><div class="wpb_column vc_column_container vc_col-sm-12"><div class="vc_column-inner"><div class="wpb_wrapper">
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>With this tutorial, we will create a shortcode that will return the results of a WordPress query.</p>
<p>We will be creating a <a title="Add Shortcode" href="https://codex.wordpress.org/Function_Reference/add_shortcode" target="_blank" rel="noopener">add_shortcode</a> shortcode that will contain the shortcode name and function as parameters.<br />
With this example, we will call a query for a Video post type sorted by number of likes.</p>
<p>We edited the get option inside the shortcode if you have options. Then we run the new WP_Query.</p>

		</div>
	</div>
<div id="ts-enlighterjs-container-8300889" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-8300889" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="php" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">&lt;?php
// Creation du shortcode permettant de lister la liste des videos class&eacute;es par nombre de likes
add_shortcode( &#039;viavideoslikes&#039;, &#039;via_videos_list_likes_shortcode&#039; );
function via_videos_list_likes_shortcode( $atts ) {
	ob_start();
	$options = get_option(&#039;via_video_name&#039;);
	$query = new WP_Query( array(
		&#039;post_type&#039;            =&gt; &#039;viavideos&#039;,
		&#039;meta_key&#039;             =&gt; &#039;_post_like_count&#039;,
		&#039;orderby&#039;              =&gt; &#039;meta_value_num&#039;,
        &#039;order&#039;                =&gt; &#039;DESC&#039;,
		&#039;posts_per_page&#039;       =&gt; -1,
		) );
	if ( $query-&amp;gt;have_posts() ) { 
	?&gt;
	
	
	&lt;?php while ( $query-&gt;have_posts() ) : $query-&gt;the_post(); ?&gt;

	
        // Afficher ici votre contenu dynamique dans vos contenants div


	&lt;?php endwhile; wp_reset_postdata(); ?&gt;
	&lt;?php $myvariable = ob_get_clean();
	return $myvariable;
	}
}</pre></div><h2 style="text-align: left" class="vc_custom_heading vc_do_custom_heading" >Creating a Query Post Shortcode for WordPress</h2><div id="ts-enlighterjs-container-4050549" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-4050549" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="php" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">[viavideoslikes]</pre></div><h2 style="text-align: left" class="vc_custom_heading vc_do_custom_heading" >Or in a template page</h2><div id="ts-enlighterjs-container-2779998" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-2779998" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="php" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">&lt;?php echo do_shortcode(&#039;[viavideoslikes]&#039;); ?&gt;</pre></div></div></div></div></div>
</div><p>The post <a href="https://themespress.ca/en/creating-query-post-shortcode/">Creating a Query Post Shortcode for WordPress</a> first appeared on <a href="https://themespress.ca/en/">Themespress</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://themespress.ca/en/creating-query-post-shortcode/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Number of Posts Published/Edited In the last 48 hours</title>
		<link>https://themespress.ca/en/posts-published-edited-48-hours/</link>
					<comments>https://themespress.ca/en/posts-published-edited-48-hours/#respond</comments>
		
		<dc:creator><![CDATA[Daniel]]></dc:creator>
		<pubDate>Sun, 15 Aug 2021 14:02:15 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Posts]]></category>
		<category><![CDATA[Query]]></category>
		<guid isPermaLink="false">https://themespress.ca/?p=4887</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<div class="wpb-content-wrapper"><div class="vc_row wpb_row vc_row-fluid"><div class="wpb_column vc_column_container vc_col-sm-12"><div class="vc_column-inner"><div class="wpb_wrapper">
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>With this tutorial, we will learn how to create a <strong>WP Query</strong> which will return the number of posts published or edited during the last 2 days.</p>
<p>With this query, we will ping the Post Type and the results will display the Post Type counter published/edited in the last 2 days.</p>
<p>With our example, the post type is crasyphotosgalleries.<br />
We will add two arguments with the <strong><a href="https://developer.wordpress.org/reference/classes/wp_query/">date_query</a></strong>: the first one will check the <strong>post_date</strong> and/or the <strong>post_modified </strong>of the last 2 days.</p>

		</div>
	</div>
<h2 style="text-align: left" class="vc_custom_heading vc_do_custom_heading" >Create a query - Number of posts published/edited</h2>
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>With a function we will return the results within a <a href="https://themespress.ca/categorie/tutoriels/"><strong>WordPress shortcode.</strong></a></p>

		</div>
	</div>
<div id="ts-enlighterjs-container-9940351" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-9940351" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="php" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">///////////////////////////////////// Shortcode show Count Modified 48 Hours //////////////
add_shortcode( &#039;addocountpost&#039;, &#039;addo_count_posttype_modified&#039; );
function addo_count_posttype_modified(){ 
	$args = array(
		&#039;post_type&#039; =&gt; &#039;crasyphotosgalleries&#039;,
		&#039;date_query&#039; =&gt; array(
			&#039;relation&#039;   =&gt; &#039;OR&#039;,
			array(
				&#039;column&#039;  =&gt; &#039;post_date&#039;,
				&#039;after&#039;   =&gt; &#039;-2 days&#039;
			),
			array(
				&#039;column&#039;  =&gt; &#039;post_modified&#039;,
				&#039;after&#039;   =&gt; &#039;-2 days&#039;
			)
		)
	);
	// query
	$updated = new WP_Query($args);
	$totalpost = $updated-&gt;found_posts; 
        return &#039;&lt;div class=&quot;addo40px addocenter&quot;&gt;&#039; . $totalpost . &#039;&lt;/div&gt;&#039;; 
}</pre></div>
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>You can use the following shortcode in your <strong>content</strong>:</p>

		</div>
	</div>
<div id="ts-enlighterjs-container-3061752" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-3061752" class="ts-enlighterjs-pre-nohighlight" style="" data-enlighter-language="no-highlight" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">[addocountpost]</pre></div>
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>You can use the following shortcode in your <strong>templates</strong>:</p>

		</div>
	</div>
<div id="ts-enlighterjs-container-8061188" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-8061188" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="php" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">&lt;?php echo do_shortcode( &#039;[addocountpost]&#039; ); ?&gt;</pre></div></div></div></div></div>
</div><p>The post <a href="https://themespress.ca/en/posts-published-edited-48-hours/">Number of Posts Published/Edited In the last 48 hours</a> first appeared on <a href="https://themespress.ca/en/">Themespress</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://themespress.ca/en/posts-published-edited-48-hours/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Get Post/Page quantity by user role</title>
		<link>https://themespress.ca/en/get-post-page-quantity-by-user-role/</link>
					<comments>https://themespress.ca/en/get-post-page-quantity-by-user-role/#respond</comments>
		
		<dc:creator><![CDATA[Daniel]]></dc:creator>
		<pubDate>Fri, 26 Feb 2021 16:16:47 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Posts]]></category>
		<category><![CDATA[Query]]></category>
		<guid isPermaLink="false">https://themespress.ca/?p=4189</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<div class="wpb-content-wrapper"><div class="vc_row wpb_row vc_row-fluid"><div class="wpb_column vc_column_container vc_col-sm-12"><div class="vc_column-inner"><div class="wpb_wrapper">
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>With this tutorial, we will create new WordPress functions which will get the quantity of posts or post types by user role.<br />
In the example below, the role will be <strong>chroniqueur</strong>. If we want to add a new user role, we need a new function such as the function below. Make sure to assign users to your roles if necessary.</p>

		</div>
	</div>
<div id="ts-enlighterjs-container-9905455" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-9905455" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="php" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">/**************************************** Add a new role Member ***********************************/

function themespress_role_partenaire() {  
    //add the new user role
    add_role(
        &#039;chroniqueur&#039;,
        &#039;Chroniqueur&#039;,
        array(
            &#039;read&#039;         =&gt; true,
            &#039;delete_posts&#039; =&gt; false
        )
    );
 
}
add_action(&#039;admin_init&#039;, &#039;themespress_role_partenaire&#039;);</pre></div>
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>And then we need to query the database by checking how many posts or post types are associated with the user. Within the function, we need to set the role with the user; you can replace news_writer by author for example.</p>
<p>With this function, we will stock the variable used to query the database for the post or post type parameter.<strong>$post_type</strong></p>

		</div>
	</div>
<div id="ts-enlighterjs-container-5081330" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-5081330" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="php" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">function count_chahuts_by_author($post_type){
// Change here the user role
       $user_query = new WP_User_Query( array( &#039;role&#039; =&gt; &#039;chroniqueur&#039; ) );
	// Get the total number of users for the current query. I use (int) only for sanitize.
	$users_count = (int) $user_query-&gt;get_total();
	// Echo a string and the value
	return $users_count;
}</pre></div>
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>Now we will create a shortcode that will return the value of the function above. For example our shortcode will be: [chroniqueurchahutcount]</p>
<p>For our example, the shortcode will return the quantity of <strong>chahuts</strong> post type which will match the <strong>chroniqueur</strong> user. </p>

		</div>
	</div>
<div id="ts-enlighterjs-container-3341203" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-3341203" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="php" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">/////////////////////////////////////// Shortcode count chahut ///////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////

function shortcode_chroniqueurs_count_chahut(){
$user_ID = get_current_user_id(); 
return count_chahuts_by_author($user_ID, &#039;chahuts&#039;);
}
add_shortcode(&#039;chroniqueurchahutcount&#039;, &#039;shortcode_chroniqueurs_count_chahut&#039;);</pre></div>
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>Add your [chroniqueurchahutcount] shortcode in your template or your <a href="https://shareasale.com/r.cfm?b=841990&amp;u=1476870&amp;m=64739&amp;urllink=&amp;afftrack=" target="_blank" rel="noopener"><strong>formidable form</strong></a>.</p>
<p>Be careful as this tutorial will generate the result for a user connected with their user_id (current_user).</p>

		</div>
	</div>
</div></div></div></div>
</div><p>The post <a href="https://themespress.ca/en/get-post-page-quantity-by-user-role/">Get Post/Page quantity by user role</a> first appeared on <a href="https://themespress.ca/en/">Themespress</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://themespress.ca/en/get-post-page-quantity-by-user-role/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Display an Author&#8217;s Post on a Page Template</title>
		<link>https://themespress.ca/en/display-an-authors-post-on-a-page-template/</link>
					<comments>https://themespress.ca/en/display-an-authors-post-on-a-page-template/#respond</comments>
		
		<dc:creator><![CDATA[Daniel]]></dc:creator>
		<pubDate>Sat, 11 Apr 2020 18:44:38 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Query]]></category>
		<category><![CDATA[Users]]></category>
		<guid isPermaLink="false">https://themespress.ca/?p=4193</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<div class="wpb-content-wrapper"><div class="vc_row wpb_row vc_row-fluid"><div class="wpb_column vc_column_container vc_col-sm-12"><div class="vc_column-inner"><div class="wpb_wrapper">
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>With this tutorial, we will create a query which will display posts or post types of an author. This could be used in a scenario where a user wants to see their ads on an online classified advertising service.</p>
<p>First off, you must know that the <a href="https://developer.wordpress.org/themes/basics/template-hierarchy/" target="_blank" rel="noopener noreferrer">author.php</a> template could fill our need, however this is will be to create a more custom result.</p>
<p>First off, if not already done, you&#8217;ll need to create a <a href="https://developer.wordpress.org/themes/template-files-section/page-template-files/" target="_blank" rel="noopener noreferrer">template page in English</a>.</p>
<p>Once the template is ready to go, you will be able to add your query to it and create your loop. For that, we will use the <a href="https://developer.wordpress.org/reference/functions/get_posts/" target="_blank" rel="noopener noreferrer">get_posts</a> function to display our results.</p>
<p>In the example below, we have a news post type that displays this template which displays a user&#8217;s published news post. <br />
Simply replace News by your post type. You will then be able to edit the arguments such as pagination, etc&#8230;</p>

		</div>
	</div>
<div id="ts-enlighterjs-container-2062291" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-2062291" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="php" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">&lt;?php
$args = array(
&#039;posts_per_page&#039; =&gt; 100,  // Limit to 5 posts
&#039;post_type&#039; =&gt; &#039;nouvelles&#039;,  // Query for the default Post type
&#039;order_by&#039; =&gt; &#039;post_date&#039;  // Order by date posted
);
$last_five_posts = get_posts( $args );

foreach ( $last_five_posts as $post ) : setup_postdata( $post ); 
?&gt;
&lt;?php /// Votre HTML / R&Eacute;SULTATS ICI ?&gt;
&lt;?php endforeach; wp_reset_postdata(); ?&gt;</pre></div></div></div></div></div>
</div><p>The post <a href="https://themespress.ca/en/display-an-authors-post-on-a-page-template/">Display an Author’s Post on a Page Template</a> first appeared on <a href="https://themespress.ca/en/">Themespress</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://themespress.ca/en/display-an-authors-post-on-a-page-template/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WordPress: Display Posts of the Month with get_posts</title>
		<link>https://themespress.ca/en/wordpress-display-posts-of-the-month-with-get_posts/</link>
					<comments>https://themespress.ca/en/wordpress-display-posts-of-the-month-with-get_posts/#respond</comments>
		
		<dc:creator><![CDATA[Daniel]]></dc:creator>
		<pubDate>Sun, 22 Apr 2018 18:19:34 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Query]]></category>
		<guid isPermaLink="false">https://themespress.ca/?p=5041</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<div class="wpb-content-wrapper"><div class="vc_row wpb_row vc_row-fluid"><div class="wpb_column vc_column_container vc_col-sm-12"><div class="vc_column-inner"><div class="wpb_wrapper">
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>With this tutorial, we&#8217;ll show you how to use a query with the database so that it displays posts or Post Types that were published during any given month.</p>
<p>The <a href="https://codex.wordpress.org/Template_Tags/get_posts" target="_blank" rel="noopener">get_posts</a> is a great tool to search within a database but it can restrict the usable parameters. It can simplifies queries in any page template.</p>
<p>It also allows us to display a number of results via the post_per_page without pagination. We will need to make sure to close our query with<br />
<strong>wp_reset_postdata();</strong>.</p>
<p>In our example below, we&#8217;ve configured <strong>posts_per_page</strong> to -1 because we want to display the current month only. Our Post Type is <strong>viavideos</strong>, so either replace it by your or <strong>‘post’</strong> for articles.</p>
<p>As you can see, we need to stock two different variables in the dates which represent the current month and year. Then with our parameters we need to do a <a href="https://codex.wordpress.org/Class_Reference/WP_Query" target="_blank" rel="noopener">date_query</a> and add our two date parameters.</p>
<p>And then we close the loop to display our results.</p>

		</div>
	</div>
<h2 style="text-align: left" class="vc_custom_heading vc_do_custom_heading vc_custom_1664649280627" >Display Post or Post Type of the month with the get_posts function.</h2><div id="ts-enlighterjs-container-2782266" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-2782266" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="php" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">&lt;?php
$year = date(&#039;Y&#039;); 
$month = date(&#039;m&#039;); 
$args = array( 
	&#039;posts_per_page&#039;    =&gt; -1,
	&#039;post_type&#039;         =&gt; &#039;viavideos&#039;,
	&#039;date_query&#039;        =&gt; array(
	array(
		&#039;year&#039;  =&gt; $year,
		&#039;month&#039; =&gt; $month,
	),
),
);
 
$posts = get_posts( $args );
foreach( $posts as $post ) :  setup_postdata($post); ?&gt;
&lt;?php /// Votre div dynamique d&eacute;sir&eacute;e ?&gt;
&lt;?php endforeach; wp_reset_postdata(); ?&gt;</pre></div></div></div></div></div>
</div><p>The post <a href="https://themespress.ca/en/wordpress-display-posts-of-the-month-with-get_posts/">WordPress: Display Posts of the Month with get_posts</a> first appeared on <a href="https://themespress.ca/en/">Themespress</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://themespress.ca/en/wordpress-display-posts-of-the-month-with-get_posts/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Display User&#8217;s Liked Articles in Their Account</title>
		<link>https://themespress.ca/en/display-users-liked-articles-in-account/</link>
					<comments>https://themespress.ca/en/display-users-liked-articles-in-account/#respond</comments>
		
		<dc:creator><![CDATA[Daniel]]></dc:creator>
		<pubDate>Wed, 03 Jan 2018 15:01:41 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Query]]></category>
		<guid isPermaLink="false">https://themespress.ca/?p=5112</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<div class="wpb-content-wrapper"><div class="vc_row wpb_row vc_row-fluid"><div class="wpb_column vc_column_container vc_col-sm-12"><div class="vc_column-inner"><div class="wpb_wrapper">
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>With this tutorial, we will show you how to display the articles liked by a user in their account. We need to create a query that will display the posts with the post meta &#8220;like&#8221; and its value are equal to the WordPress user&#8217;s ID.</p>
<p>Obviously, to be make this function works, we need a Like system so users can like posts such as this one: <a href="https://github.com/JonMasterson/WordPress-Post-Like-System" target="_blank" rel="noopener">WordPress Post Like System</a></p>
<p>You also need a user account and do not forget the conditions in the user&#8217;s profile page.</p>

		</div>
	</div>
<div id="ts-enlighterjs-container-1479035" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-1479035" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="php" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">&lt;?php 
if ( ! defined( &#039;ABSPATH&#039; ) ) exit; // Exit if accessed directly 
if ( is_user_logged_in()) : 
global $current_user; 
wp_get_current_user();
$user = $current_user-&gt;ID; 
?&gt;
</pre></div><h2 style="text-align: left;font-family:Abril Fatface;font-weight:400;font-style:normal" class="vc_custom_heading vc_do_custom_heading" >Display posts liked by the user</h2>
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>In their user account, we will display the list of recently liked post. This create this query, we fist need to fetch the user&#8217;s ID with <strong>get_current_user_id()</strong> via WordPress&#8217; get_currentuserinfo(). Next, the <strong>$types</strong> variable with fetch the required Post Type <strong>(In our example it&#8217;s Listings. Simply replace it by your Post Type or article post)</strong>. We will display 10 and then we&#8217;ll run a <a href="https://codex.wordpress.org/Class_Reference/WP_Meta_Query" target="_blank" rel="noopener">meta_query</a> that will match the author&#8217;s ID and the post meta key.</p>
<p>Now we will loop. We implement an incremented ranking with <strong>$i</strong>. Here&#8217;s our query:<br />
(The user_liked key must be changed by your post meta key representing the Like)</p>

		</div>
	</div>
<div id="ts-enlighterjs-container-2169674" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-2169674" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="php" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">&lt;?php
	$author_id = get_current_user_id();
	$types = &#039;listings&#039;;
	$args = array(
	  &#039;numberposts&#039; =&gt; &#039;10&#039;,
	  &#039;post_type&#039; =&gt; $types,
	  &#039;meta_query&#039; =&gt; array (
		array (
		  &#039;key&#039; =&gt; &#039;_user_liked&#039;,
		  &#039;value&#039; =&gt; $author_id,
		  &#039;compare&#039; =&gt; &#039;LIKE&#039;
		)
	  ) ); 
	$like_query = new WP_Query( $args );
	if ( $like_query-&gt;have_posts() ) :	?&gt;
	&lt;ul class=&quot;user-likes&quot;&gt;
		&lt;?php $i = 1; while ( $like_query-&gt;have_posts() ) : $like_query-&gt;the_post(); ?&gt;
			 &lt;li&gt;
				 &lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot; title=&quot;&lt;?php the_title_attribute(); ?&gt;&quot;&gt;
				 &lt;?php echo $i; ?&gt; &lt;?php _e(&#039;-&#039;); ?&gt;
				 &lt;?php the_title(); ?&gt;
				&lt;/a&gt;
			&lt;/li&gt;
		&lt;?php $i++; endwhile; ?&gt;
	&lt;/ul&gt;
	&lt;?php else : ?&gt;
	&lt;p&gt;&lt;?php _e( &#039;Pas de J&amp;#39;aime&#039;, &#039;via-entreprises&#039; ); ?&gt;&lt;/p&gt;
	&lt;?php 
	endif; 
	wp_reset_postdata(); 
?&gt;</pre></div></div></div></div></div>
</div><p>The post <a href="https://themespress.ca/en/display-users-liked-articles-in-account/">Display User’s Liked Articles in Their Account</a> first appeared on <a href="https://themespress.ca/en/">Themespress</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://themespress.ca/en/display-users-liked-articles-in-account/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Display number of posts per author</title>
		<link>https://themespress.ca/en/display-number-of-posts-per-author/</link>
					<comments>https://themespress.ca/en/display-number-of-posts-per-author/#respond</comments>
		
		<dc:creator><![CDATA[Daniel]]></dc:creator>
		<pubDate>Thu, 20 Apr 2017 21:39:39 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Query]]></category>
		<category><![CDATA[Users]]></category>
		<guid isPermaLink="false">https://themespress.ca/?p=6181</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<div class="wpb-content-wrapper"><div class="vc_row wpb_row vc_row-fluid"><div class="wpb_column vc_column_container vc_col-sm-12"><div class="vc_column-inner"><div class="wpb_wrapper">
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p><strong>Display number of posts per author: </strong> With this tutorial, we will create a simply query that will allow you to display the number of posts per author on your author.php template.</p>
<p>In order to do so, we will use the <a href="https://codex.wordpress.org/Function_Reference/count_user_posts" target="_blank" rel="noopener">count user posts</a> WordPress function.</p>

		</div>
	</div>
<div id="ts-enlighterjs-container-7263972" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-7263972" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="php" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">&lt;?php $user_post_count = count_user_posts( $userid , $post_type ); ?&gt;</pre></div>
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>We will take this example and tailor it to our query. First, we need to configure <strong>global $authordata;</strong> to fetch the authors&#8217; data. And then in a variable, we will use the author ID along with count_user_posts with our arguments.</p>
<p>In our example, our Post Type is called produits-listings.</p>

		</div>
	</div>
<div id="ts-enlighterjs-container-5072433" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-5072433" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="php" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">&lt;?php 
global $authordata; 
//author id 
$post_author = $authordata-&gt;ID; 
//Ici nous ajoutons notre variable author ID + nom du Pot Type 
echo &#039;&#039; . count_user_posts( $post_author, &quot;produits-listings&quot; ); 
?&gt;</pre></div>
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>Finally, the number of Post Type per author will be displayed within your author.php template. Nice and easy.</p>

		</div>
	</div>
</div></div></div></div>
</div><p>The post <a href="https://themespress.ca/en/display-number-of-posts-per-author/">Display number of posts per author</a> first appeared on <a href="https://themespress.ca/en/">Themespress</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://themespress.ca/en/display-number-of-posts-per-author/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Display a post list if Post Meta Key is empty</title>
		<link>https://themespress.ca/en/display-post-list-post-meta-key-empty/</link>
					<comments>https://themespress.ca/en/display-post-list-post-meta-key-empty/#respond</comments>
		
		<dc:creator><![CDATA[Daniel]]></dc:creator>
		<pubDate>Wed, 05 Apr 2017 21:55:18 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Query]]></category>
		<guid isPermaLink="false">https://themespress.ca/?p=6185</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<div class="wpb-content-wrapper"><div class="vc_row wpb_row vc_row-fluid"><div class="wpb_column vc_column_container vc_col-sm-12"><div class="vc_column-inner"><div class="wpb_wrapper">
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>Display Posts with an Post Meta Key empty: With this tutorial, we will create a query that will allow you to display WordPress Posts or Post Types even if they have an empty Post Meta.</p>
<p>With our example, we created a query that will check the viavideos Post Type and link it to Post Meta Key. You can add additional arguments if need be. We will use the showposts to display the quantity.</p>
<p>Here&#8217;s the code to add into your template or other and tailor it to your query with meta_query this way:</p>

		</div>
	</div>
<div id="ts-enlighterjs-container-5276651" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-5276651" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="standard" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">&lt;?php 
///// Nous construisons nos arguments requ&ecirc;te ///// 
$args = array( 
&#039;post_type&#039; =&gt; &#039;viavideos&#039;, 
&#039;showposts&#039; =&gt; &#039;500&#039;, 
///// Nous construisons nos arguments meta query en sp&eacute;cifiant relation AND ///// 
&#039;meta_query&#039; =&gt; array( 
&#039;relation&#039; =&gt; &#039;AND&#039;, 
array( 
&#039;key&#039; =&gt; &#039;informations&#039;, 
&#039;value&#039; =&gt; &#039;&#039;, 
&#039;compare&#039; =&gt; &#039;NOT EXISTS&#039; 
) 
) 
); 
$via_query = new WP_Query( $args ); 
?&gt;
// The Loop
&lt;?php if ( $via_query-&gt;have_posts() ) { while ( $via_query-&gt;have_posts() ) { $via_query-&gt;the_post(); ?&gt;
&lt;li&gt;&lt;article&gt;&lt;?php the_title(); ?&gt;&lt;/article&gt;&lt;/li&gt;
&lt;?php } ?&gt;
&lt;?php } else { ?&gt;
// no posts found
&lt;?php } ?&gt;

// Restore original Post Data
&lt;?php wp_reset_postdata(); ?&gt;</pre></div>
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>Don&#8217;t forget to update the Post Type and your Post Meta Key.</p>

		</div>
	</div>
</div></div></div></div>
</div><p>The post <a href="https://themespress.ca/en/display-post-list-post-meta-key-empty/">Display a post list if Post Meta Key is empty</a> first appeared on <a href="https://themespress.ca/en/">Themespress</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://themespress.ca/en/display-post-list-post-meta-key-empty/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Display the Number of WooCommerce Products</title>
		<link>https://themespress.ca/en/display-the-number-of-woocommerce-products/</link>
					<comments>https://themespress.ca/en/display-the-number-of-woocommerce-products/#respond</comments>
		
		<dc:creator><![CDATA[Daniel]]></dc:creator>
		<pubDate>Tue, 08 Nov 2016 23:06:14 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Query]]></category>
		<category><![CDATA[WooCommerce]]></category>
		<guid isPermaLink="false">https://themespress.ca/?p=6252</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<div class="wpb-content-wrapper"><div class="vc_row wpb_row vc_row-fluid"><div class="wpb_column vc_column_container vc_col-sm-12"><div class="vc_column-inner"><div class="wpb_wrapper">
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>This tutorial will show you how to create a query to display all of your WooCommerce products.</p>
<p>First a quick explaination of <strong><a href="https://developer.wordpress.org/reference/hooks/found_posts/" target="_blank" rel="noopener">found_posts</a></strong> which can be seen in the query below. It will allow you to filter the number of products found and matching the Posts ou Post Types inside your arguments.</p>
<p>For everything else, it&#8217;s a simple and basic query for WooCommerce. The post for WooCommerce products is simply called <strong>product</strong>.</p>

		</div>
	</div>
<h2 style="text-align: left" class="vc_custom_heading vc_do_custom_heading" >Display the Number of WooCommerce Products</h2><div id="ts-enlighterjs-container-4829037" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-4829037" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="standard" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">function via_classement_woocommerce_products_count_total() {
    $args = array( &#039;post_type&#039; =&gt; &#039;product&#039;, &#039;post_status&#039; =&gt; &#039;publish&#039;, &#039;posts_per_page&#039; =&gt; -1 );
	$products = new WP_Query( $args );
	echo &#039;&lt;span class=&quot;numberCircle&quot;&gt;&#039;;
	echo $products-&gt;found_posts;
	echo &#039;&lt;/span&gt;&#039;;
}</pre></div>
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>Here&#8217;s how we can avoid multiplying your functions if you want to use the same function but you want to display the number of product by status:<br />
Here are the various <a href="https://codex.wordpress.org/Post_Status" target="_blank" rel="noopener">post_status</a> of your posts or Post Types:<br />
&#8211; &#8216;publish&#8217; == Published<br />
&#8211; &#8216;Future&#8217; == Scheduled<br />
&#8211; &#8216;Draft&#8217; == Draft<br />
&#8211; &#8216;Pending&#8217; == Pending Review<br />
&#8211; &#8216;Private&#8217; == Private<br />
&#8211; &#8216;Trash&#8217; == Deleted</p>
<p>Now let&#8217;s build the previous function considering we want to display the number of products and their status.</p>
<p>Here&#8217;s the function to add in your <strong>functions.php</strong> file. Note that we stored a  <strong>$statut</strong> variable that will allow us to fetch the value that we want to assign to it. Said value is display as such: <strong>&#8216;post_status&#8217; =&gt; $statut</strong>.</p>

		</div>
	</div>
<div id="ts-enlighterjs-container-2248271" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-2248271" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="standard" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">function via_classement_woocommerce_products_count_total($statut) {
    $args = array( &#039;post_type&#039; =&gt; &#039;product&#039;, &#039;post_status&#039; =&gt; $statut, &#039;posts_per_page&#039; =&gt; -1 );
	$products = new WP_Query( $args );
	echo &#039;&lt;span class=&quot;numberCircle&quot;&gt;&#039;;
	echo $products-&gt;found_posts;
	echo &#039;&lt;/span&gt;&#039;;
}</pre></div>
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>Now in the desired WordPress php  template file, display the function this way:</p>

		</div>
	</div>
<div id="ts-enlighterjs-container-6939537" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-6939537" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="standard" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">&lt;?php echo via_classement_woocommerce_products_count_total($statut = &#039;publish&#039;); ?&gt;</pre></div></div></div></div></div>
</div><p>The post <a href="https://themespress.ca/en/display-the-number-of-woocommerce-products/">Display the Number of WooCommerce Products</a> first appeared on <a href="https://themespress.ca/en/">Themespress</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://themespress.ca/en/display-the-number-of-woocommerce-products/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Excluding the Current ID With a Query Post Type</title>
		<link>https://themespress.ca/en/excluding-the-current-id-with-a-query-post-type/</link>
					<comments>https://themespress.ca/en/excluding-the-current-id-with-a-query-post-type/#respond</comments>
		
		<dc:creator><![CDATA[Daniel]]></dc:creator>
		<pubDate>Tue, 11 Oct 2016 22:11:52 +0000</pubDate>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Query]]></category>
		<guid isPermaLink="false">https://themespress.ca/?p=6270</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<div class="wpb-content-wrapper"><div class="vc_row wpb_row vc_row-fluid"><div class="wpb_column vc_column_container vc_col-sm-12"><div class="vc_column-inner"><div class="wpb_wrapper">
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p> With this WordPress tutorial, we will create a query that will allow you to exclude the current ID from your Post Type.</p>
<p>In our example, we already have a Post Type called <strong>Services</strong>. Let&#8217;s say we want to consult one of our services, WordPress will get the data from the <strong>single-services.php</strong> file and if WordPress doesn&#8217;t find this file, it will call <strong>single.php</strong>.</p>
<p>If you don&#8217;t have a <strong>single-posttype.php</strong> file (Ex:single-services.php), make sure to create it if you want to be able to customize it with HTML and CSS.</p>
<p>Once your file is ready, let&#8217;s add our Query Post Type in our sidebar DIV by excluding the current post ID.</p>

		</div>
	</div>
<h2 style="text-align: left" class="vc_custom_heading vc_do_custom_heading" >Excluding the Current ID With a Query Post Type</h2><div id="ts-enlighterjs-container-5019804" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-5019804" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="php" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">&lt;?php 
$i = 1; 
$currentID = get_the_ID(); 
$temp = $wp_query; 
$wp_query = null; 
$wp_query = new WP_Query( 
	array( 
		&#039;post_type&#039;      =&gt; &#039;services&#039;, 
		&#039;showposts&#039;      =&gt; &#039;5&#039;, 
		&#039;post__not_in&#039;   =&gt; array($currentID) 
	)
); 

while ($wp_query-&gt;have_posts()) : $wp_query-&gt;the_post(); ?&gt;

/// Votre loop ici 
&lt;?php echo $i; ?&gt;

&lt;?php $i++; endwhile; ?&gt;
&lt;?php 
$wp_query = null; $wp_query = $temp; 
// Reset 
?&gt;</pre></div>
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>The first line, <strong>$i = 1;</strong>, will allow you to increment by 1 and starting from 1. This means we wil count by number the query order of your services. So if your loop, you can display the sorting number this way:</p>

		</div>
	</div>
<div id="ts-enlighterjs-container-5836594" class="ts-enlighterjs-container-single-enabled  " style="width: 100%;  margin-top: 0px; margin-bottom: 0px;" data-enlighter-doubleclick="true" data-enlighter-windowbutton="true" data-enlighter-windowtext="New Window" data-enlighter-rawbutton="true" data-enlighter-rawtext="RAW Code" data-enlighter-infobutton="false" data-enlighter-infotext="EnlighterJS" data-enlighter-indent="2"><pre id="ts-enlighterjs-pre-5836594" class="" style="white-space: pre-wrap; height: 100%; margin: 0; padding: 0;" data-enlighter-language="php" data-enlighter-theme="enlighter" data-enlighter-group="" data-enlighter-title="" data-enlighter-linenumbers="true" data-enlighter-lineoffset="1" data-enlighter-highlight="">&lt;?php echo $i; ?&gt;</pre></div>
	<div class="wpb_text_column wpb_content_element" >
		<div class="wpb_wrapper">
			<p>In our second line of our <strong>Query Post Type</strong>, we will store the current ID in a variable in order to exclude it with post_not_in (&#8216;post__not_in&#8217; => array($currentID)).</p>
<p>Reference: <a href="https://developer.wordpress.org/reference/functions/get_the_id/" target="_blank" rel="noopener">get_the_ID();</a><br />
This will display the results of your Post Type in the sidebar except the current page.</p>

		</div>
	</div>
</div></div></div></div>
</div><p>The post <a href="https://themespress.ca/en/excluding-the-current-id-with-a-query-post-type/">Excluding the Current ID With a Query Post Type</a> first appeared on <a href="https://themespress.ca/en/">Themespress</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://themespress.ca/en/excluding-the-current-id-with-a-query-post-type/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
