-
-
Save tommcfarlin/c8eb7e636f9cd42f80908a94af7946a6 to your computer and use it in GitHub Desktop.
[WordPress] Adding Custom Information to a WordPress Category Edit Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('edit_category_form', 'acme_display_object_ids'); | |
/** | |
* Displays an ordered list of all of the object IDs for a given | |
* taxonomy. | |
*/ | |
function acme_display_object_ids() | |
{ | |
// Code for displaying the Object IDs goes here. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ObjectIdSubscriber | |
{ | |
/** | |
* @var string the hook to which this class subscribes | |
*/ | |
private $hook; | |
/** | |
* @param string $hook the hook to which this class is registered with WordPress | |
*/ | |
public function __construct(string $hook) | |
{ | |
$this->hook = $hook; | |
} | |
/** | |
* Renders all of the information for the object IDs. | |
*/ | |
public function load() | |
{ | |
// Code for displaying the Object IDs goes here. | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This will retrieve all of the term relationships from where we can get post IDs. | |
global $wpdb; | |
$termTaxonomyId = $wpdb->get_results( | |
$wpdb->prepare( | |
" | |
SELECT DISTINCT term_taxonomy_id | |
FROM $wpdb->term_taxonomy | |
WHERE term_id = %s | |
", | |
$tagId | |
), | |
ARRAY_A | |
); | |
$termTaxonomyId = isset($termTaxonomyId[0]) ? $termTaxonomyId[0] : null; | |
if (null === $termTaxonomyId) { | |
return null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This will retrieve all of the post IDs. | |
$postIds = $wpdb->get_results( | |
$wpdb->prepare( | |
" | |
SELECT object_id | |
FROM $wpdb->term_relationships | |
WHERE term_taxonomy_id = %s | |
", | |
$termTaxonomyId | |
), | |
ARRAY_A | |
); | |
if (empty($postIds)) { | |
return null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
<?php foreach ($postIds as $postId) : ?> | |
<li><?php echo $postId; ?></li> | |
<?php endforeach; ?> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment