EDIT: I am going to simplify this whole question. If I have domain.com/something/{$variable} how do I retrieve that $variable to use in a query within my template. This is really the extent of the issue.
I am having a lot of difficulties with what I thought should have been a very basic query. But wordpress's taxonomy system is making things difficult.
I am utilizing bricks, metabox, and JET Engine plugins, which will allow me to properly create M:M relations between a HOBBY CPT and about a dozen others. One will be articles.
I can set up the database, I can set up the single post templates on both sides, And automatically generate a link so that my Hobby page, displays domain.com/{child_cpt}s/for/{HOBBY}
Ie domain.com/articles/for/baseball or domain.com/photos/for/baseball, etc.
or i can do domain.com/baseball/articles and individual articles would just use a domain.com/article/article_slug etc
I can do all that.
What I can't figure out is how to get the index page of child_cpts based on the defined {Hobby-slug} in the url.
Everyone keeps telling me to use categories. But that would require me to enter the 1000+ topics once as a post type and again as a taxonomy. That is stupid. I just need to pull the variable. that follows /for/{$hobby}
I've seen a few posts on here that look like they're probably what I need, but I dont understand the code structure enough to know how to modify it for my needs. Is there something I can enter in a code block for my bricks builder template to pull the variable from the url? Once I get that variable, I can take it from there.
Get custom post type slug for an archive page
I am trying to set things up in dedicated DB tables for optimization, but some post types may just stay in the default post table.
But a standard pivot table is created for my M:M relations.
EDIT:
I manually created a menu as I dont think wordpress has a default solution for dynamic tags.
<ul>
<li id="menu-item"
class="menu-item menu-item-type-custom menu-item-object-custom bricks-menu-item">
<a href="/hobby/<?php $hobby; ?>">Hobby</a></li>
<li id="menu-item"
class="menu-item menu-item-type-custom menu-item-object-custom bricks-menu-item">
<a href="/articles/for/<?php $hobby; ?>">Articles</a></li>
<li id="menu-item"
class="menu-item menu-item-type-custom menu-item-object-custom bricks-menu-item">
<a href="/groups/for/<?php $hobby; ?>">Groups</a></li>
<li id="menu-item"
class="menu-item menu-item-type-custom menu-item-object-custom bricks-menu-item">
<a href="/books/for/<?php $hobby; ?>">Books</a></li>
<li id="menu-item"
class="menu-item menu-item-type-custom menu-item-object-custom bricks-menu-item">
<a href="/resources/for/<?php $hobby; ?>">Resources</a></li>
<li id="menu-item" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item bricks-menu-item">
<div class="brx-submenu-toggle icon-right">
<a href="#">Media</a>
<button aria-expanded="false" aria-label="Media Sub menu">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 12" fill="none" class="menu-item-icon"><path d="M1.50002 4L6.00002 8L10.5 4" stroke-width="1.5"></path></svg></button></div>
<ul class="sub-menu">
<li id="menu-item" class="menu-item menu-item-type-custom menu-item-object-custom menu-item bricks-menu-item">
<a href="/photos/for/<?php $hobby; ?>">Photos</a></li>
<li id="menu-item" class="menu-item menu-item-type-custom menu-item-object-custom menu-item bricks-menu-item">
<a href="/video/for/<?php $hobby; ?>">Video</a></li>
<li id="menu-item" class="menu-item menu-item-type-custom menu-item-object-custom menu-item bricks-menu-item">
<a href="/audio/for/<?php $hobby; ?>">Audio</a></li>
</ul>
</li>
</ul>
If i use the code provided by sally I would need to add $hobby=hobby_filter();
But i am not sure what I am supposed to do with the rewrite rule. It may be needed, and i understand what the code is doing i think, but I'm not sure how to apply it to my situation.
I think a get_query_var() method is needed somewhere so the value can be utilized within the bricks or jet engine query builder.
If I were doing this with Laravel Id have a route as
Route::get('/articles/for/{hobby:slug}', 'ArticlesFrontendController@index')->name('article.browse');
and a corresponding controller with
public function index(Hobby $hobby)
{
$articles = Article::where('status','published')->whereHas('hobbies', function ($query) use ($hobby) {
$query->where('hobby_id',$hobby->id);
})->with(['users:id,username',
...])->get();
return view('articles.frontend.index', compact('articles', 'hobby'));
}
where the hobby slug gets passed to pull the proper object
This would produce the query "select articles where hobby = $hobby "
Then I simply loop through the $articles in the view.
The hobby post type itself has three taxonomies and a dozen custom fields already attached to it, so it has to be a custom post type.
WordPress in general is missing any good way to relate posts to each other. I provided this suggested update, but who knows if they will consider it.
The best way to think of this is as a group or a business who may have members, reviews, departments, clients, etc related to it. It is easy enough to put related items links on the parent page itself, but trying to get the related items on a separate page is proving difficult.