Global variable $post returning incorrect object

Why is test-product-magazine, instead of the correct, shop? The global $post object is not a reliable way to determine anything about archive pages because the object will typically be the first post of the main query when outside the loop. Since the main query is for the posts in the archive and not the archive … Read more

Changing number of posts per page on CPT-archive.php, have tried 20-30 code chunks so far

Using the Query Monitor suggested by @Andrew (Thanks, Andrew!) I found a little gem in my parent theme that overrides everything set in my function. I found out wordpress loads the child themes functions.php first myfunction{ $query->set( ‘posts_per_page’, 15 ); } so when it later loaded lameparentfunction{ $query->set( ‘posts_per_page’, 5 ); } It undid the … Read more

How can i change the output of posts_nav_link();

posts_nav_link() just outputs get_previous_posts_link() and get_next_posts_link() with a separator between them. The helpful thing is does is handle the visibility of the separator depending on whether both pages exist. Since you always want to show something on either side, you don’t need it. What you can do is output the next and previous links manually, … Read more

List taxonomies according to whether this post is in another taxonomy in taxonomy archive

Well I got there, my public brain functions for all to see, hopefully someone somewhen will pass this was and find it useful. The code; // First get the type $term = get_term_by( ‘slug’, get_query_var( ‘term’ ), get_query_var( ‘taxonomy’ ) ); $type = $term->slug; // we need to do some comparisons, here’s the variable $this_instance … Read more

How to get “last year from [spec year] that has posts”?

You could do a query for a single post made before the currently viewed year. When sorted by date in descending order (the default) the first result will be from the most recent year with posts. $current_year = get_query_var( ‘year’ ); $previous_posts = get_posts( array( ‘numberposts’ => 1, ‘date_query’ => array( ‘year’ => $current_year, ‘compare’ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)