Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor fireproofsocks

    (@fireproofsocks)

    Could you define what you mean by “duplicate” data?

    Setting up the data structure for a site can take a fair amount of thought. What have you tried so far?

    Thread Starter prionnsias

    (@prionnsias)

    Hi,
    what i mean by duplicate data is basically

    team 1
    coach – john
    Player – lucy
    ref – bill

    team 2
    coach – Lucy
    Player – Bill
    ref – John

    John is on 2 teams, once as a coach, another as the ref
    I want to be able to go to “John’s Page”
    and see the teams he was on and what job he did
    using the CCTM plug in i can see what each team is made up of, but i don’t know how to get it to tell me what teams each person is on, and what they do on that team

    hope that makes sense

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    If I were doing this, I would have 2 custom content types: teams, and people. The “team” type would use “Relation” custom fields that would let you choose players and refs (i.e. “people” posts).

    So if you view John’s page, you need to do a reverse query to see which teams are referencing John in any capacity. In a pseudo-query, you’d have this type of logic: “SELECT teams WHERE player=John OR WHERE ref=John”.

    You can do this with WP’s querying functions, but I got so frustrated with their incompleteness, caveats, and lack of consistency that I wrote a separate plugin for this type of scenario: Summarize Posts. It’s going to be part of the CCTM core in the upcoming 0.9.5 version, but for now 0.7 is an independent download.

    Using Summarize Posts, you’d want to review this:
    http://code.google.com/p/wordpress-summarize-posts/wiki/Examples_get_posts

    First you have to get the post_id of John’s page… this is different depending on whether you are inside or outside the loop (groan), but it usually is something like this:

    global $post;
    $johns_id = $post->ID;

    Then you need to use $johns_id in your query. In your single-person.php theme file, you’d put some PHP code like this:

    $Q = new GetPostsQuery();
    $args = array();
    $args['post_type'] = 'team';
    $args['meta_key'] = 'player';
    $args['meta_value'] = $johns_id;
    $results = $Q->get_posts($args);
    
    foreach ($results as $r) {
       // iterates over all teams where John is a player
    }
    
    $Q = new GetPostsQuery();
    $args = array();
    $args['post_type'] = 'team';
    $args['meta_key'] = 'ref';
    $args['meta_value'] = $johns_id;
    $results = $Q->get_posts($args);
    
    foreach ($results as $r) {
       // iterates over all teams where John is a ref
    }

    You may want to download the dev version of Summarize Posts, just because I’m in the middle of updating it, and I fixed a couple bugs since 0.7.

    Or if you want to check out WP’s options for this, look at WP_Query() or get_posts(), but the basic idea is the same: you need to find the posts that have referenced John’s id in a custom field.

    Thread Starter prionnsias

    (@prionnsias)

    Wow.
    thank you very much. I need to wrap my head around this but i believe what your saying will work, it is just a bit beyond my current understanding of code. but i will give it a try
    thank you very much!

    Plugin Contributor fireproofsocks

    (@fireproofsocks)

    OR… you can try one of the theme functions… quite a bit simpler to follow, but a heavier load on the database:

    http://code.google.com/p/wordpress-custom-content-type-manager/wiki/TemplateFunctions#get_posts_sharing_custom_field_value

    $results = get_posts_sharing_custom_field_value('ref', $post->ID);
    foreach ($results as $r) {
    //... do something with each
    }

    The above example assumes a custom field name of “ref”, and it’ll return all posts that have used the current post ID for that value (e.g. if you’re looking at Jeff’s page, then $post->ID will correspond to Jeff).

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘[Plugin: Custom Content Type Manager] Pull Duplicate data’ is closed to new replies.