Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
open-source
Guaraci WordPress Plugin
Commits
9240c4fa
Commit
9240c4fa
authored
5 years ago
by
Rafael Chaves Freitas
Browse files
Options
Download
Email Patches
Plain Diff
Função para retornar termos de uma taxonomia pela ordem de utilização
parent
81633343
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
library/functions.php
library/functions.php
+59
-0
No files found.
library/functions.php
View file @
9240c4fa
...
...
@@ -12,4 +12,63 @@ function template_part($template_name, $params = []){
extract
(
$params
);
include
$template_filename
;;
}
/**
* Retorna uma lista de termos ordenados pela data de utilização.
*
* @param string $taxonomy
* @param integer $limit
* @param integer $paged
* @return \WP_Term[]
*/
function
get_terms_order_by_posts_publish_date
(
string
$taxonomy
,
int
$limit
=
10
,
int
$paged
=
1
){
global
$wpdb
;
if
(
false
)
$wpdb
=
new
\
wpdb
(
1
,
2
,
3
,
4
);
$offset
=
$limit
*
(
$paged
-
1
);
$sql
=
"
SELECT
t.term_id,
t.name,
t.slug,
tx.term_taxonomy_id,
tx.taxonomy,
tx.description,
tx.parent,
tx.count
FROM
$wpdb->terms
t
LEFT JOIN
$wpdb->term_taxonomy
tx ON tx.term_id = t.term_id
LEFT JOIN
$wpdb->term_relationships
tr ON tr.term_taxonomy_id = tx.term_taxonomy_id
LEFT JOIN
$wpdb->posts
p ON p.ID = tr.object_id
WHERE
tx.taxonomy = '
$taxonomy
' AND
p.post_type = 'coluna' AND
tr.object_id IN (
SELECT
MAX(object_id)
FROM
$wpdb->term_relationships
WHERE
term_taxonomy_id = tr.term_taxonomy_id
)
GROUP BY tx.term_taxonomy_id
ORDER BY p.post_date DESC
LIMIT
$limit
OFFSET
$offset
"
;
$results
=
$wpdb
->
get_results
(
$sql
);
$terms
=
array_map
(
function
(
$term
){
return
new
\
WP_Term
(
$term
);
},
$results
);
return
$terms
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment