0

I'll make an example to ask if what I plan to do is possible with Wordpress, and eventually, how.

[Wordpress Site] Posts fully made through custom fields data

Single post structure:
 - (A) Custom field artist name
 - (B) Custom field artist profil pic
 - (C) Custom field element description
 - (D) Custom field element image

Post #1:
 - Custom field artist name (John Cena)
 - Custom field artist profil pic (johncena.jpg)
 - Custom field element description (John Cena F-U to Hogan)
 - Custom field element image (johncena_fu_hogan.jpg)

Post #2:
 - Custom field artist name (John Cena)
 - Custom field artist profil pic (johncena.jpg)
 - Custom field element description (John Cena destroyed by Lesnar)
 - Custom field element image (johncena_F5eved.jpg)

Post #3:
 - Custom field artist name (John Cena)
 - Custom field artist profil pic (johncena.jpg)
 - Custom field element description (John Cena announces retirement)
 - Custom field element image (johncena_retirement.jpg)

Post #4:
 - Custom field artist name (Randy Orton)
 - Custom field artist profil pic (randyorton.jpg)
 - Custom field element description (Orton vs. Undertaker)
 - Custom field element image (orton_vs_taker.jpg)

Post #5:
 - Custom field artist name (Randy Orton)
 - Custom field artist profil pic (randyorton.jpg)
 - Custom field element description (Orton injured by Lesnar)
 - Custom field element image (orton_injury_lesnar.jpg)

As you can see, every post regarding a certain artist, have the same first 2 custom fields, used as introduction. While the remaining 2 always differs.

Now my question...

Is there any way to customize search results page (the one called by a custom search, a tag or a certain category list, which usually is index.php) all posts of a certain artist, showing first 2 custom fields only once, and the remaining 2 fields for all present posts?

Example: url: mysite.com/tag/john-cena

Result:
 - Custom field A
 - Custom field B

 - Custom field C
 - Custom field D

 - Custom field C
 - Custom field D

 - Custom field C
 - Custom field D

Is this technically possible by inserting a certain variable like "if A and B = true, do not repeat" ??

1 Answer 1

1

For a tag/ category page you can use the following to get the slug/name of the queried object e.g. John Cena

$queried_object = get_queried_object(); var_dump( $queried_object );

You can then enter that into a meta query to gather all the posts that have the artists name field as your queried object. However for this to work the name entered in you field needs to match that of the tag/category.

Meta query info can be found here: https://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

Hope that points you in the right direction.

Sign up to request clarification or add additional context in comments.

2 Comments

So you mean something like this? $args = array( 'meta_value' => 'John Cena', 'meta_value' => 'johncena.jpg' ); $query = new WP_Query( $args );
More like $args = array( 'meta_value' => 'John Cena', 'meta_key' => 'field_name' ); $query = new WP_Query( $args ); Where field_name if the name of the custom field that you have created for the Artist name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.