Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

jchunick on "Custom post, custom taxonomy, missing relationship"

$
0
0

The Preamble:
I'm building a website for our hospital. On it we have a left side area on which is going to be populated what we are naming a 'Call to Action'. This 'Call to Action' is a custom post I have created. I have also created a custom taxonomy which will allow me to set a 'Call to Action' as being one of a list of categories such as 'Volunteer', 'Foundation', 'Did You Know', etc. Setting the category for a Call to Action does two things:

  1. Allow for certain pages with aligned messages to display the appropriate 'Call to Action'. For instance, pages about Volunteering would show Volunteer 'Calls to Action'.
  2. It will help style the Call to Action container/content appropriately.

It should also be noted that I have added a custom meta field to the Pages editor. This meta field pulls the 'calltoaction' taxonomy list and displays it as a group of checkbox options. This will allow the person editing the page to select which 'Calls to Action' are allowed to be shown on the given page.

What I would like to happen:

  1. When I create a new page I select which 'Calls to Action' are allowed to show on that page
  2. When someone goes to that page, code that's in the custom template of the page will:
    • get the allowed calls to action for the page
    • use WP_Query() to get a random 'Call to Action'
    • pass parameters to the function to limit the collection of records to the allowed 'calls to action'.

What is actually happening:
Up to this point, all my code and customizations work correctly. I am able to get a single, random 'Call to Action' to show. However, when I try to pass the array of allowed 'Calls to Actin' to the query it's not working.

Here's the code that works:

$args=array('post_type'=>'calltoaction', 'orderby'=>'rand', 'posts_per_page'=>'1');
$calltoaction = new WP_Query($args);

Here's the code I would like to get working:

$supported_cta = get_post_meta(get_the_ID(), 'supported_cta', true);
$where = array(
               'key' => 'cta_category',
               'value' => $supported_cta,
               'compare' => 'IN'
              );
$args=array('post_type'=>'calltoaction', 'orderby'=>'rand', 'posts_per_page'=>'1', 'meta_query'=>$where);
$calltoaction = new WP_Query($args);

Please let me know if you need more information or if screenshots of the custom post and taxonomy would help.


Viewing all articles
Browse latest Browse all 8245

Trending Articles