How to get wordpress empty content list - wordpress

i make two list theme
1.the posts have featured image and title, but empty content. i want get this list.
2.and other posts with content list.
I don't have any idea, help me please

Try to use below code:
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'ID',
'order' => 'desc');
$blank_posts = array();
$posts = new WP_Query( $args );
if ( $posts->have_posts() ) :
while ( $posts->have_posts() ) : $posts->the_post();
$content = get_the_content();
if($content == '') {
array_push( $blank_posts, $post);
}
endwhile;
endif;
/* print all blank content posts */
//echo "<pre>"; print_r($blank_posts);
/* loop */
if(!empty($blank_posts)){
foreach ($blank_posts as $pst) {
echo "ID= ". $pst->ID . ', '. "Title= ". $pst->post_title .'<hr />';
}
}

Related

Shortcode display featured image and permalink from pages in Wordpress

I am trying to make a shortcode that can display featured image and permalink from chosen pages on my front-page in Wordpress.
It works fine to display one page, but I want to be able to choose different pages. I cannot figure out how....
// Creating Shortcodes with parameter to display pages
function my_shortcode_display_pages($attr, $content = null){
//call global variable
global $post;
// Defines Shortcode's Attributes
$shortcode_args = shortcode_atts(
array(
'type' => '',
'pagename' => '',
'num' => '',
'order' => ''
), $attr);
// set an array with query arguments
$args = array(
'post_type' => $shortcode_args['type'],
'pagename' => $shortcode_args['pagename'],
'posts_per_page' => $shortcode_args['num'],
'order' => $shortcode_args['order']
);
// get posts
$recent_posts = get_posts($args);
$output = '<div class="cards">';
$query = new WP_Query($args);
if($query->have_posts()) :
while($query->have_posts()) :
$query->the_post() ;
$output .= '<div class="card">' . ''.get_the_post_thumbnail() .'<h2 class="entry-title-index">'.get_the_title() .'</h2>'.'</div>';
endwhile;
wp_reset_postdata();
endif;
//return the output.
return $output . '</div>';
}
// Register the shortcode.
add_shortcode( 'my_display_pages', 'my_shortcode_display_pages' );
[my_display_pages pagename="hotell"]

wordpress custom Query, Two columns of content, How do I get two paging function?

There are many pages, but how to get paging?
Two columns of content have two paging.
i need paging for Two columns of content.
how to do this?
and if you can tell me how to add the function of the comments, I will thank you even more.
look this:
https://stackoverflow.com/a/45451489/1266305
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'ID',
'order' => 'desc');
$blank_posts = array();
$content_post =array();
$posts = new WP_Query( $args );
if ( $posts->have_posts() ) :
while ( $posts->have_posts() ) : $posts->the_post();
global $post;
$content = get_the_content();
if(empty($content)) {
array_push( $blank_posts, $post);
}else{
array_push( $content_post, $post);
}
endwhile;
endif;
/* blank content posts */ /* loop */
if(!empty($blank_posts)){
foreach ($blank_posts as $pst) {
echo "<pre>"; print_r($blank_posts);
echo $pst->post_title;
}
};
/* have content posts */
if(!empty($content_post)){
foreach ($content_post as $pst) {
echo '<a href='. $pst->guid .'>' .$pst->post_title. '</a> ';
}
}

Custom Wp_Query still uses the main post id

On my Wordpress website, I have the following code:
if ( is_page( 8 ) ) {
include_once('somecustompage.php');
}
And in my somecustompage.php, I use a custom WP_Query:
// WP_Query arguments
$args = array (
'post_type' => 'farewell',
'post_status' => 'publish',
'pagination' => true,
'posts_per_page' => '10',
'sticky' => false
);
// The Query
$current_farewell_query = new WP_Query( $args );
// The Loop
if ( $current_farewell_query->have_posts() ) {
$current_farewells = '<table><tr><th>NAME</th><th>LOCATION</th><th>FAREWELL</th></tr>';
while ( $current_farewell_query->have_posts() ) {
$farewell_name = ( get_field('name') ? get_field('name') : '' );
$chapels = wp_get_post_terms( get_the_ID(), 'chapels', array('fields' => 'name') );
$current_farewell_query->the_post();
$current_farewells .= '<tr>';
$current_farewells .= '<td>' . $farewell_name . '</td>';
$current_farewells .= '<td></td>';
$current_farewells .= '<td></td>';
$current_farewells .= '</tr>';
}
$current_farewells .= '</table>';
} else {
$current_farewells = 'No Current Farewells.';
}
// Restore original Post Data
wp_reset_postdata();
However, when I try to use the post IDs within this custom loop, both get_the_ID() and $post->ID return 8, which is the main page post id. I need to use the new post IDs that are returned in the new query.
Anybody knows how to resolve this?
I found where the problem was. Everything should've been called after this line: $current_farewell_query->the_post(); for the query to work as expected.

Make query_posts exclude post based on a term in the post title

Posts on my page are fetched via this query:
<?php
$limit = get_option('posts_per_page');
query_posts(array(
'showposts'=>62,
'more' => $more = 0,
'v_sortby' => 'views',
'v_orderby' => 'DESC',
'v_outtype' => 'content',
'v_timespan' => 'year',
'paged' => $paged
));?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
However, I want to exclude all posts which title contains the word "Metal".
I know there's a 'post__not_in' => feature, but I'm not sure how to implement it.
I tried
$exclude1 = get_page_by_title('Metal'); and then including
'post__not_in' => array($exclude1->ID,$exclude2->ID)
but that seems to center around pages, and not post titles itself.
In the arguments:
$args['special_search'] = 'Metal';
In your functions.php:
add_filter( 'posts_where', 'special_search_posts_where', 10, 2 );
function special_search_posts_where( $where, $query ) {
if (isset($query->query_vars["special_search"])) {
global $wpdb;
$where .= ' AND ' . $wpdb->posts . '.post_title NOT LIKE \'%' . $query->query_vars["special_search"] . '%\'';
}
return $where;
}

wp how to exclude filter from the custom query

I am trying to exclude a filter (slug) from a loop. I am researched exclude and have tried it in various places in the code. Usually I break the page. This is the code, I am attempting to change to exclude the slug 20. It is a filter named 'american'. I have tried to exclude at the beginning of the array, didn't work; then, I tried after the foreach($catz as $cat) section. I tried this ‘exclude=20&title_li=' . I tried cat=-20 and various other combinations. Any help would be very very appreciated.
// The Custom Query
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => $counter_folio,
'paged' => $paged,
'order' => 'DESC'
);
query_posts( $args );
while( have_posts() ) : the_post();
$color = substr(get_option('dcb_dynamic_color'), 1);
// Get the original thumbnail of the post
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), false, '' );
$excerpt = get_the_excerpt();
// Get the custom fields
$vimeo = get_post_meta($post->ID, "vimeo", true);
$youtube = get_post_meta($post->ID, "youtube", true);
// Get the filter > Category of item
$catz = wp_get_object_terms($post->ID,'filters');
foreach($catz as $cat){
$currcat = $cat->slug;
$catname = $cat->name;
break;
}
$counter++;
?>
If you want to filter the post with id 20 simple exclude it with the following code
// The Custom Query
$args = array(
'post_type' => 'portfolio',
'posts_per_page' => $counter_folio,
'paged' => $paged,
'order' => 'DESC'
);
query_posts( $args );
while( have_posts() ) : the_post();
$color = substr(get_option('dcb_dynamic_color'), 1);
// Get the original thumbnail of the post
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), false, '' );
$excerpt = get_the_excerpt();
// Get the custom fields
$vimeo = get_post_meta($post->ID, "vimeo", true);
$youtube = get_post_meta($post->ID, "youtube", true);
// Get the filter > Category of item
$catz = wp_get_object_terms($post->ID,'filters');
foreach($catz as $cat){
if($cat->slug != 'american')
{
$currcat = $cat->slug;
$catname = $cat->name;
break;
}
}
$counter++;

Resources