WordPress.org

Forums

WP Invoices Ultimate
custom query to show invoices by client id (9 posts)

  1. Augusto
    Member
    Posted 2 years ago #

    Hello!
    I'm trying to make a page with a custom query, showing only the invoices of a specific client/id.

    make a new query for the custom post type is easy, but how can I add some parameters to show only the invoices of a specific client?

    I know that the wp-invoice data is stored in a hidden custom field for each post (_wpiu_invoice_meta), and I could make a query using the args "meta_value"/"meta_query", but how to make a query that check a key of the custom field array?

    thank!!

    http://wordpress.org/extend/plugins/wp-invoice-ultimate/

  2. Jeremy Plack
    Member
    Posted 2 years ago #

    Hi,
    I'm trying to do the same only I can't even query all invoices, when I try it gives me regular posts instead of invoices, here is my code:

    $args = array( 'post-type' => 'wpiu-invoices', 'posts_per_page' => 10 );
    $loop = new WP_Query ( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    	the_title();
    	echo '<div class="entry-content">';
    	the_content();
    	echo '</div>';
    endwhile;
  3. Jeremy Plack
    Member
    Posted 2 years ago #

    well now I got my invoice query working for some reason it didn't like the array.
    This worked:

    $query = new WP_Query( 'post_type=wpiu-invoices' );
    while ( $query->have_posts() ) : $query->the_post();
    	the_title();
    	echo '<div class="entry-content">';
    	the_content();
    	echo '</div>';
    endwhile;
  4. Augusto
    Member
    Posted 2 years ago #

    yes, it will work, but isn't a solution for my problem..
    How to use the correct args to filter the invoices of a specific client?

    Any ideias?

  5. matthew.james.allan
    Member
    Posted 1 year ago #

    This is the loop I use. I am using a heavily modified version of the plugin so I haven't tested this with the original but it should work.

    $query = new WP_Query(array ('meta_key' => '_wpiu_invoices_meta', 'post_type' => 'wpiu-invoices' ));
    while ( $query->have_posts() ) : $query->the_post();
    
    	//get meta, get user ids
    	$meta = get_post_meta($post->ID, '_wpiu_invoices_meta',true);
    	$invoice_client = $wp_query->current_post->$meta['_wpiu_invoices_meta_client'];
    	$current_user = wp_get_current_user()->ID;
    
    	if($current_user == $invoice_client) { 
    
    }
    endwhile;
  6. matthew.james.allan
    Member
    Posted 1 year ago #

    oops, the line that declares $invoice_client should be:

    $invoice_client = $meta['_wpiu_invoices_meta_client'];

  7. Augusto
    Member
    Posted 1 year ago #

    Thanks @matthew.james.allan

    I'll test it!

  8. Kenan
    Member
    Posted 1 year ago #

    I need exactly what matthew.james.allan posted, but just cannot get that code work. :(

    there is an IF statement, but nothing inside...should I ask some echo?

    I need simple list of all invoices for current user...
    Any help please?
    Thanks.

  9. Kenan
    Member
    Posted 1 year ago #

    Done!
    There was a typo in matthew.james.allan's code.

    <?php
    $meta = get_post_meta($post->ID, '_wpiu_invoice_meta',true);
    $invoice_client = $meta['_wpiu_invoice_meta_client'];
    $current_user = wp_get_current_user()->ID;
    $query = new WP_Query(array ('meta_key' => '_wpiu_invoice_meta', 'post_type' => 'wpiu-invoices' ));
          while ($query->have_posts()) : $query->the_post();
          if($current_user->ID == $meta['_wpiu_invoice_meta_client'])
    	{
        echo '<ul><li><a href='; the_permalink(); echo '>'; the_title();  echo '     on     ';  the_date(); echo'</a></li></ul>';
    	}
          endwhile;
    ?>

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic