{"id":6185,"date":"2017-04-05T17:55:18","date_gmt":"2017-04-05T21:55:18","guid":{"rendered":"https:\/\/themespress.ca\/?p=6185"},"modified":"2022-09-03T11:35:00","modified_gmt":"2022-09-03T15:35:00","slug":"display-post-list-post-meta-key-empty","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/display-post-list-post-meta-key-empty\/","title":{"rendered":"Display a post list if Post Meta Key is empty"},"content":{"rendered":"<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\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<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>\n<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>\n<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>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-2592517\" 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-2592517\" 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 \n\/\/\/\/\/ Nous construisons nos arguments requ&ecirc;te \/\/\/\/\/ \n$args = array( \n&#039;post_type&#039; =&gt; &#039;viavideos&#039;, \n&#039;showposts&#039; =&gt; &#039;500&#039;, \n\/\/\/\/\/ Nous construisons nos arguments meta query en sp&eacute;cifiant relation AND \/\/\/\/\/ \n&#039;meta_query&#039; =&gt; array( \n&#039;relation&#039; =&gt; &#039;AND&#039;, \narray( \n&#039;key&#039; =&gt; &#039;informations&#039;, \n&#039;value&#039; =&gt; &#039;&#039;, \n&#039;compare&#039; =&gt; &#039;NOT EXISTS&#039; \n) \n) \n); \n$via_query = new WP_Query( $args ); \n?&gt;\n\/\/ The Loop\n&lt;?php if ( $via_query-&gt;have_posts() ) { while ( $via_query-&gt;have_posts() ) { $via_query-&gt;the_post(); ?&gt;\n&lt;li&gt;&lt;article&gt;&lt;?php the_title(); ?&gt;&lt;\/article&gt;&lt;\/li&gt;\n&lt;?php } ?&gt;\n&lt;?php } else { ?&gt;\n\/\/ no posts found\n&lt;?php } ?&gt;\n\n\/\/ Restore original Post Data\n&lt;?php wp_reset_postdata(); ?&gt;<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>Don&#8217;t forget to update the Post Type and your Post Meta Key.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"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<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/display-post-list-post-meta-key-empty\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4627,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[322],"class_list":["post-6185","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-query"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=6185"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6185\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4627"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}