Excuse me if something like this has been asked before. So, I'm trying to alter the query which displays the posts of a custom post type, but on the admin side, more precisely, the edit.php page. This is my code:
function my_function() {
global $pagenow, $typenow;
if( 'edit.php' == $pagenow && 'certain-post-type' === $typenow ) {
// do something
}
}
add_action( 'admin_init', 'my_function' );
The main problem is not altering the query itself (yet!), but targeting only the edit.php page which lists the custom-post-type posts. It works when I hook onto the admin_init
hook, but I understand that admin_init
runs on every admin page load, which seems a bit unnecessary. I tried limiting this to fire only on the edit.php page for the custom post type by setting the hook to
add_action( 'load-edit.php', 'my_function' );
, but this did nothing.
Couldn't find much documentation on the load-{$pagenow}
hook, hopefully the community can steer me in the right direction and tell me what I did wrong?
admin_init
, and you've left out what you were doing in your question and replaced it with// do something
, can you restore the hidden code in your question and expand on the context? As well as why you need to do this and what the modification is? The answer to this question if taken literally isn't going to be very useful to you if your goal is to modify the querypre_get_posts
is the answer I was going to write but then I re-read your question further and got confused because you're doing other things and haven't shared them. Can you use the edit link to re-add the code you mentioned but did not include? Note that not everybody reads comments so they'll have the same questions and confusions I have if not others. Also how is the role mapped to the term? How do we know that for "Specific role" we need to limit toterm1
and notterm2
? What are you trying to implement that requires this?