ist es möglich, eine Schleife von Beiträgen mit WP_Query oder query_posts unter Verwendung des Titels zu erstellen?
dh
$args = array('post_title'='LIKE '.$str.'% ');
$res = WP_Query($arg);
// the loop...
// trying this now...
$mypostids = $wpdb->get_col("select ID from $wpdb->posts where post_title like 'Abb%' ");
echo count($mypostids).", "; // works but can't echo out array of IDs for the next args?
$args = array(
'post__in'=> $mypostids
);
$res = WP_Query($args);
while( $res->have_posts() ) : $res->the_post(); ...
habe dies mit Hilfe dieses Beitrags zum Abschluss gebracht. Prost;
$finalArgs = array (
'posts_per_page'=>5,
'order' => 'ASC',
'post_type' => 'school'
);
// Create a new instance
$searchSchools = new WP_Query( $finalArgs );
$mypostids = $wpdb->get_col("select ID from $wpdb->posts where post_title LIKE '".$str."%' ");
$args = array(
'post__in'=> $mypostids,
'post_type'=>'school',
'orderby'=>'title',
'order'=>'asc'
);
$res = new WP_Query($args);
while( $res->have_posts() ) : $res->the_post();
global $post;
$EstablishmentNumber = get_post_meta($post->ID,'EstablishmentNumber', true);
$schl = array('id'=>$EstablishmentNumber, 'label'=>$post->post_title , 'value'=>$EstablishmentNumber );
$matchedSchools[] = $schl;
endwhile;
functions.php
<?php
add_filter( 'posts_where', 'title_like_posts_where', 10, 2 );
function title_like_posts_where( $where, $wp_query ) {
global $wpdb;
if ( $post_title_like = $wp_query->get( 'post_title_like' ) ) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql( $wpdb->esc_like( $post_title_like ) ) . '%\'';
}
return $where;
}
?>
Dann:
$args = array(
'post_title_like' => $str
);
$res = new WP_Query($args);
Holen Sie sich den Titel aus einer anderen Schleife
$title = get_the_title();
und verwenden Sie die Variable $ title, wenn Sie möchten.
<?php
global $post, $current_post_id, $title;
function filter_where($where = ''){
global $title;
$where .= "AND post_title = '$title'";
return $where;
}
add_filter('posts_where', 'filter_where');
$query = new WP_Query(array('post_type' => 'sessions') );
if ( have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
/* Loop here */
endwhile; endif;
wp_reset_query(); ?>
Ja, es ist möglich....
global $wpdb;
$mypostids = $wpdb->get_col("select ID from $wpdb->posts where post_title like '%$str%' ");
$args = array('post__in'=$mypostids);
$res = WP_Query($arg);
Diese Antworten scheinen mir ein Versuch zu sein, WordPress zu hacken.
Lesen Sie die gleiche Frage zum Stapelüberlauf:
https://stackoverflow.com/questions/25761593/wp-query-with-post-title-like-something-and-category
Dies funktioniert, wenn Sie eine Suchabfrage nach Titel, sortiert nach Titel, durchführen möchten:
$the_query = new WP_Query(
array(
'post_type' => 'watches',
'posts_per_page' => 5,
'orderby' => 'title',
's' => 'my title'
)
);
Diese Beispielabfrage bezieht sich auf einen Beitragstyp mit dem Namen "watches" und das "s" (Suchbegriff) ist der Ort, an dem Sie in der Abfrage nach Ihren Beitragstiteln suchen können