Creating an archive page listing external data
Creating an archive page listing external data
Creating an archive page listing external data
Custom post type archives don’t have year/month rewrite rules, they only have a single archive which will be at /press/ and /more_posts/. If you want those, you’ll have to add them yourself. For the taxonomy, add the taxonomies argument to your post type registration to insure the two objects are connected, see the note about … Read more
Use wp_get_object_terms function to get any taxonomy you want, category, tag, state, etc. For example: $terms = wp_get_object_terms(get_the_ID(), ‘state’); $state = array_pop($terms); echo $state->name; This function is returning array of terms, so in case you only have one state, it will return array of one item in it.
You can use pre_get_posts in your functions file for this with the WP_Query order and orderby parameters. function alter_query( $query ) { if ( $query->is_archive() && $query->is_main_query() && !is_admin()) { $query->set( ‘posts_per_page’, 100 ); } } add_action( ‘pre_get_posts’, ‘alter_query’ );
you can name the file in this way: taxonomy-{taxonomy}.php as described in this page, there you can create a loop adn WP will only select the elements of the given taxonomy.
Apart from the horribly format issues you also have a typo: <?php $my_excerpt = $item->post_excerpt; if ($my_excerpt){ echo Str::limit($my_excerpt, 120);} else $content = ($item->post_content);{ $contentexcerpt = substr($content, 0, 150); echo $contentexcerpt, ‘…’; } ?> These lines: else $content = ($item->post_content);{ should be: else { $content = ($item->post_content); The parser registered a single line of code … Read more
is_archive() not working on selected “Posts page”
Weird slug in archives permalink
I added this to my child-theme’s functions.php file and it works 100% add_action( ‘template_redirect’, ‘redirect_archive’ ); function redirect_archive() { if ( is_tax(‘location’) ) { $termurl = get_query_var( ‘term’ ); wp_redirect( home_url(‘/search/location/’.$termurl), 301 ); exit; } }
There’s an easier way, don’t bother with the page at all. Instead, store the content inside an option or theme mod, and use the settings API/customiser to edit the content. To turn the textarea holding the content in your form into a full editor, use the wp_editor function to get a wysiwyg editor that looks … Read more