ريد مساعدة في طريقة تغير عمل اضافة وردبريس لعدم خبرتي فلي البرمجة
اضافة Query Multiple Taxonomies
وتعمل الاضافة علي عرض أكثر من تصنيف رئيسي
مثال
site.com/?cat1=test1&cat2=test2
في الوضع الافتراضي للاضافة في lists mode
أذا تم الضغط علي تصنيف فرعي لل cat1 أو cat2 يتم اضافة التصنيف للرابط مثال
site.com/?cat1=test1+test3&cat2=test2
أريد التعديل علي الاضافة لكي تعمل اذا تم الضغط علي التصنيف الفرعي test3 يتم التبديل بينه وبين test 1
كمثال site.com/?cat1=test3&cat2=test2
أي جعل العلاقة OR للتصنيفات الفرعيه بدل AND
اعتقد الملف المسؤل عن هذه العملية ف الاضافة
\[code\]<?php
class QMT\_Hooks {
// Transform ?qmt\[category\]\[\]=5&qmt\[category\]\[\]=6 into something usable
function request( $request ) {
if ( !isset( $\_GET\['qmt'\] ) )
return $request;
foreach ( $\_GET\['qmt'\] as $taxonomy => $terms ) {
$request\['tax\_query'\]\[\] = array(
'taxonomy' => $taxonomy,
'terms' => $terms,
'field' => 'term\_id',
'operator' => 'IN'
);
}
return $request;
}
// Add the selected terms to the title
function wp\_title( $title, $sep, $seplocation ) {
$tax\_title = QMT\_Template::get\_title();
if ( empty( $tax\_title ) )
return $title;
if ( 'right' == $seplocation )
$title = "$tax\_title $sep ";
else
$title = " $sep $tax\_title";
return $title;
}
function wp\_head() {
?>
<style type="text/css">
.taxonomy-drilldown-lists p,
.taxonomy-drilldown-checkboxes p,
.taxonomy-drilldown-dropdowns p {
margin-top: 1em;
}
.taxonomy-drilldown-checkboxes li,
.taxonomy-drilldown-dropdowns li {
list-style: none;
}
.taxonomy-drilldown-dropdowns select {
display: block;
}
</style>
<?php
}
}
scbHooks::add( 'QMT\_Hooks' );
class QMT\_Terms {
private static $filtered\_ids;
// Get a list of all the terms attached to all the posts in the current query
public function get( $tax ) {
self::set\_filtered\_ids();
if ( empty( self::$filtered\_ids ) )
return array();
$raw\_terms = wp\_get\_object\_terms( self::$filtered\_ids, $tax );
// distinct terms
$terms = array();
foreach ( $raw\_terms as $term )
$terms\[ $term->term\_id \] = $term;
return $terms;
}
private function set\_filtered\_ids() {
global $wp\_query;
if ( isset( self::$filtered\_ids ) )
return;
$args = array\_merge( $wp\_query->query, array(
'fields' => 'ids',
'nopaging' => true,
'no\_found\_rows' => true,
'ignore\_sticky\_post' => true,
'cache\_results' => false,
) );
$query = new WP\_Query;
self::$filtered\_ids = $query->query( $args );
}
}
class QMT\_Count {
// Count posts, without getting them
public function get( $query\_vars ) {
$query\_vars = array\_merge( $query\_vars, array(
'fields' => 'ids',
'qmt\_count' => true,
'nopaging' => true
) );
$query = new WP\_Query( $query\_vars );
if ( !empty( $query->posts ) )
return $query->posts\[0\];
return 0;
}
function posts\_clauses( $bits, $wp\_query ) {
if ( $wp\_query->get( 'qmt\_count' ) ) {
if ( empty( $bits\['groupby'\] ) ) {
$what = '\*';
} else {
$what = 'DISTINCT ' . $bits\['groupby'\];
$bits\['groupby'\] = '';
}
$bits\['fields'\] = "COUNT($what)";
}
return $bits;
}
}
add\_filter( 'posts\_clauses', array( 'QMT\_Count', 'posts\_clauses' ), 10, 2 );
class QMT\_URL {
public function for\_tax( $taxonomy, $value ) {
$query = qmt\_get\_query();
if ( empty( $value ) )
unset( $query\[ $taxonomy \] );
else
$query\[ $taxonomy \] = trim( implode( '+', $value ), '+' );
return self::get( $query );
}
public function get( $query = array() ) {
$url = self::get\_base();
if ( empty($query) )
return apply\_filters( 'qmt\_reset\_url', $url );
ksort( $query );
foreach ( $query as $taxonomy => $value )
$url = add\_query\_arg( get\_taxonomy( $taxonomy )->query\_var, $value, $url );
return apply\_filters( 'qmt\_url', $url, $query );
}
public function get\_base() {
static $base\_url;
if ( empty( $base\_url ) )
$base\_url = apply\_filters( 'qmt\_base\_url', get\_bloginfo( 'url' ) );
return trailingslashit( $base\_url );
}
}
class QMT\_Template {
public function get\_title() {
$title = array();
foreach ( qmt\_get\_query() as $tax => $value ) {
$terms = preg\_split( '/\[+,\]+/', $value );
$out = array();
foreach ( $terms as $slug ) {
$term\_obj = get\_term\_by( 'slug', $slug, $tax );
if ( $term\_obj )
$out\[\] = $term\_obj->name;
}
$tax\_obj = get\_taxonomy( $tax );
if ( count( $out ) == 1 )
$key = $tax\_obj->labels->singular\_name;
else
$key = $tax\_obj->labels->name;
$title\[\] .= $key . ': ' . implode( ' + ', $out );
}
return implode( '; ', $title );
}
}
/\*\*
\* Wether multiple taxonomies are queried
\* @param array $taxonomies A list of taxonomies to check for (AND).
\*
\* @return bool
\*/
function is\_multitax( $taxonomies = array() ) {
$queried = array\_keys( qmt\_get\_query() );
$count = count( $taxonomies );
if ( !$count )
return count( $queried ) > 1;
return count( array\_intersect( $queried, $taxonomies) ) == $count;
}
/\*\*
\* Get the list of selected terms
\*
\* @param string $taxname a certain taxonomy name
\*
\* @return array( taxonomy => query )
\*/
function qmt\_get\_query( $taxname = '' ) {
global $wp\_query;
$qmt\_query = array();
if ( !is\_null( $wp\_query->tax\_query ) ) {
foreach ( $wp\_query->tax\_query->queries as &$tax\_query ) {
$terms = \_qmt\_get\_term\_slugs( $tax\_query );
if ( 'AND' == $tax\_query\['operator'\] )
$qmt\_query\[ $tax\_query\['taxonomy'\] \] = $terms;
if ( 'IN' == $tax\_query\['operator'\] )
$qmt\_query\[ $tax\_query\['taxonomy'\] \]\[\] = implode( ',', $terms );
}
foreach ( $qmt\_query as &$value )
$value = implode( '+', $value );
}
if ( $taxname ) {
if ( isset( $qmt\_query\[ $taxname \] ) )
return $qmt\_query\[ $taxname \];
return false;
}
return $qmt\_query;
}
// https://core.trac.wordpress.org/ticket/21684
function \_qmt\_get\_term\_slugs( &$tax\_query ) {
if ( 'slug' == $tax\_query\['field'\] )
return $tax\_query\['terms'\];
$terms = array();
foreach ( $tax\_query\['terms'\] as $field ) {
$term = get\_term\_by( $tax\_query\['field'\], $field, $tax\_query\['taxonomy'\] );
if ( $term )
$terms\[\] = $term->slug;
}
$tax\_query\['field'\] = 'slug';
$tax\_query\['terms'\] = $terms;
return $terms;
}
// Deprecated
function qmt\_get\_terms( $tax ) {
\_deprecated\_function( \_\_FUNCTION\_\_, '1.4' );
if ( is\_archive() )
return QMT\_Terms::get( $tax );
else
return get\_terms( $tax );
}\[/code\]
رابط الاضافة
http://wordpress.org/plugins/query-multiple-taxonomies/