Jump to content

doc1355

Members
  • Posts

    67
  • Joined

  • Last visited

Everything posted by doc1355

  1. Thank you. I got it to work.
  2. I have the following array, I want to sort by Date, from latest to oldest. How can I do that $array = array( 0 => array( 'id' => 5952, 'points' => 15, 'result' => 'W', 'date' => 'Jan. 2, 22', ), 1 => array( 'id' => 5965, 'points' => 6, 'result' => 'L', 'date' => 'Jan. 1, 22', ), );
  3. Thank you for your reply. But I was able to figure this out. The metadata is associated with another object. I used the ID from this object to retrieve the second object and was able to retrieve the metadata there. Thank you again for your help.
  4. No. It returns Stripe\StripeObject Object ( )
  5. When I look in Stripe dashboard, I see the metadata is saved appropriately under the price. But I don't know why it is not showing here, instead it is returning Stripe\StripeObject Object that's what I'm trying to figure out so that I can use that data.
  6. That worked for the line item. I was doing more weird stuff 🤦‍♂️ How about the [metadata]: How can I get the values in there?
  7. I have a stripe session that when I print I get the following: Stripe\LineItem Object ( [id] => li_1JwCsEAy5kUVbSuGjlYtZ6l7 [object] => item [amount_subtotal] => 2599 [amount_total] => 2340 [currency] => usd [description] => 2022 - Season 1 [price] => Stripe\Price Object ( [id] => price_1JwCsEAy5kUVbSuGHcfoxDhg [object] => price [active] => [billing_scheme] => per_unit [created] => 1637012278 [currency] => usd [livemode] => [lookup_key] => [metadata] => Stripe\StripeObject Object ( ) [nickname] => [product] => prod_KbPhMZ545KIQ90 [recurring] => [tax_behavior] => unspecified [tiers_mode] => [transform_quantity] => [type] => one_time [unit_amount] => 2599 [unit_amount_decimal] => 2599 ) [quantity] => 1 ) Stripe\LineItem Object ( [id] => li_1JwCsEAy5kUVbSuGDqbrfvRm [object] => item [amount_subtotal] => 2899 [amount_total] => 2608 [currency] => usd [description] => 2022 - Season 2 [price] => Stripe\Price Object ( [id] => price_1JwCsEAy5kUVbSuGW58akYjw [object] => price [active] => [billing_scheme] => per_unit [created] => 1637012278 [currency] => usd [livemode] => [lookup_key] => [metadata] => Stripe\StripeObject Object ( ) [nickname] => [product] => prod_KbPhcd6yq2Mrl6 [recurring] => [tax_behavior] => unspecified [tiers_mode] => [transform_quantity] => [type] => one_time [unit_amount] => 2899 [unit_amount_decimal] => 2899 ) [quantity] => 1 ) I don't know how to get the values from this data, like value of amount_total and ... Also, and more importantly, I need to get the values from [metadata]. There are two metadata information for each price, which I like to get. Thank you,
  8. Great point. Thank you for the hint and the code.
  9. Ok. I figured it out. I used getElementsByClassName instead of ID and it worked.
  10. This is brilliant. Thanks. Now I need to figure out how to get the script to work with the ID, instead of name.
  11. Thank you for your reply. 1- When I change the name of the checkbox to choice[], the javascript doesn't calculate or show the total, but you are correct, I can get all the values of the checkboxes. 2- How can I get the second value (season_id) with the current setup?
  12. I have the following array: $available_seasons = array ( 0 => array ( 'season_id' => 226, 'season_name' => '2022 - Season 1', 'season_price' => '25.99', 'season_start_date' => 'Jan. 1, 2022', 'season_end_date' => 'Mar. 31, 2022', 'prize' => 100, ), 1 => array ( 'season_id' => 227, 'season_name' => '2022 - Season 2', 'season_price' => '28.99', 'season_start_date' => 'Apr. 1, 2022', 'season_end_date' => 'Jun. 30, 2022', 'prize' => 100, ), 2 => array ( 'season_id' => 238, 'season_name' => '2022 - Season 3', 'season_price' => '40.99', 'season_start_date' => 'Jul. 1, 2022', 'season_end_date' => 'Sep. 30, 2022', 'prize' => 230, ), 3 => array ( 'season_id' => 239, 'season_name' => '2022 - Season 4', 'season_price' => '30.65', 'season_start_date' => 'Oct. 1, 2022', 'season_end_date' => 'Dec. 31, 2022', 'prize' => 300, ), ) I'm using the following loop to create the form: echo "<form name='seasonForm' method=\"post\" action='execute.php'>"; foreach ( $available_seasons as $k => $season ) { echo "<input name='choice' class='uk-checkbox' type='checkbox' value='{$season[ 'season_price' ]}' onchange='checkTotal()'/>"; } echo "<button type='submit'>Continue</button>"; I have the following JS to calculate the total price: function checkTotal() { document.seasonForm.total.value = \'\'; var sum = 0; for (i=0;i<document.seasonForm.choice.length;i++) { if (document.seasonForm.choice[i].checked) { sum = sum + (document.seasonForm.choice[i].value *1); } } document.seasonForm.total.value = "Total: $" + sum; } I am showing the total price to my users, before they click on submit. As it is, I am only able to able to get the value of one checkbox, which is season_price in my execute.php. What I need is to pass the all season_id and season_price values of the selected checkboxes to execute.php. I am not sure how to do this. Thank you for your help in advance.
  13. The script is designed so that it can create hundreds of posts at a specific time. Each post is based on a specific criteria, specific custom taxonomy. I don't think WP can do this. Also the script updates the posts based on some other criteria at a certain time.
  14. Each post content is not dynamic. However the function creates many posts at the same time based on some criteria. Old posts will remain visible and accessible.
  15. It’s a Wordpress site. Functions will create custom posts.
  16. Correct. Is that good practice? Will I be able to secure the function? Only to be run by the cron on my server and admin only?
  17. I'm developing a website for specific EVENTS. Each EVENT lasts for three months and has fixed start date and end date, and they repeat each year: Event 1: Jan. 1st – Mar. 31st Event 2: Apr. 1st – Jun. 30th Event 3: Jul. 1st – Sep. 30th Event 4: Oct. 1st – Dec. 31st I have two functions FUNCTION 1: should run 3 days before start of the event. FUNCTION 2: should run 1 day before start of last month of the event. Functions should execute only that specific event and not other future or past events. Here how the functions should run for each Event: Event 1: Jan. 1st – Mar. 31st Function 1: on Dec 29 Function 2: last day of Feb Event 2: Apr. 1st – Jun. 30th Function 1: on Mar 29 Function 2: last day of May Event 3: Jul. 1st – Sep. 30th Function 1: on Jun 28th Function 2: Last day of Aug Event 4: Oct. 1st – Dec. 31st Function 1: on Sept 28th Function 2: last day of Nov What I'm doing right now is checking today's date and comparing it to the event date. If event start date is > today and event start date < 3 then run function one. My problem/questions: As of now, I have to remember to execute the functions manually on a specific date. How can I make this automated? Can I execute the function using server Cron job? Will that be a good practice? How would you approach in checking the event date to today? I feel there maybe better way of checking the date to run the function instead of what I'm doing. I hope my question is not vague and makes sense. Thank you.
  18. I have a php page tool.php that has a function named "create_event". I want to make a button in a different page (dashboard.php), that when I click on it, it runs the "create_event" function from tool.php and shows the output from the function on dashboard.php page. I'm totally new to ajax and jquery and not sure how to do this. I did google this but not much luck. My site is build with WordPress and this is part of custom plugin that I'm making. Thank you in advance.
  19. Correction the closing tag for the tbody and table should be outside the the last foreach loop. $output = '<table class="uk-table uk-table-striped uk-table-small"><tbody>'; foreach ( $cleaned_player_id as $c ) { $output .= '<tr><td>' . $c . '</td>'; foreach ( $match_array as $m ) { if ( $m[ 'p1' ] == $c ) { $output .= '<td>' . $m[ 'p2' ] . '<br>' . $m[ 's1p1' ] . '-' . $m[ 's1p2' ] . ', ' . $m[ 's2p1' ] . '-' . $m[ 's2p2' ] . ', ' . $m[ 's3p1' ] . '-' . $m[ 's3p2' ] . '</td>'; } elseif ( $m[ 'p2' ] == $c ) { $output .= '<td>' . $m[ 'p1' ] . '<br>' . $m[ 's1p2' ] . '-' . $m[ 's1p1' ] . ', ' . $m[ 's2p2' ] . '-' . $m[ 's2p1' ] . ', ' . $m[ 's3p2' ] . '-' . $m[ 's3p1' ] . '</td>'; } } $output .= '</tr>'; } $output .= '</tbody></table>';
  20. @Barand Thanks to your last suggestion, I was able to make the table the way I wanted. Here is what I did: I add all the players to an array. I created an array to collect all the players ID, and a separate array to collect all the data for each match: while ( $match_query->have_posts() ) { $match_query->the_post(); $match_id = get_the_ID(); // Get the ID of each Match post in this event. $related_user_1 = get_post_meta( $match_id, 'related_user_1' ); $related_user_2 = get_post_meta( $match_id, 'related_user_2' ); $set_1_player_1 = get_post_meta( $match_id, 'set_1_player_1' ); $set_1_player_2 = get_post_meta( $match_id, 'set_1_player_2' ); $set_2_player_1 = get_post_meta( $match_id, 'set_2_player_1' ); $set_2_player_2 = get_post_meta( $match_id, 'set_2_player_2' ); $set_3_player_1 = get_post_meta( $match_id, 'set_3_player_1' ); $set_3_player_2 = get_post_meta( $match_id, 'set_3_player_2' ); $all_players[] = $related_user_1[ 0 ][ ' ID' ]; $all_players[] = $related_user_2[ 0 ][ ' ID' ]; $match_array[] = array( 'p1' => $related_user_1[ 0 ][ ' ID' ], 'p2' => $related_user_2[ 0 ][ ' ID' ], 's1p1' => $set_1_player_1[ 0 ] ?? '', 's1p2' => $set_1_player_2[ 0 ] ?? '', 's2p1' => $set_2_player_1[ 0 ] ?? '', 's2p2' => $set_2_player_2[ 0 ] ?? '', 's3p1' => $set_3_player_1[ 0 ] ?? '', 's3p2' => $set_3_player_2[ 0 ] ?? '', ); } Then I removed the duplicate players from the player array: $cleaned_player_id = array_unique( $all_players ); Now here comes the table: First I enter the unique player from the cleaned list into the first column. Then I loop through match data with if statement and show the results accordingly. $output = '<table class="uk-table uk-table-striped uk-table-small"><tbody>'; foreach ( $cleaned_player_id as $c ) { $output .= '<tr><td>' . $c . '</td>'; foreach ( $match_array as $m ) { if ( $m[ 'p1' ] == $c ) { $output .= '<td>' . $m[ 'p2' ] . '<br>' . $m[ 's1p1' ] . '-' . $m[ 's1p2' ] . ', ' . $m[ 's2p1' ] . '-' . $m[ 's2p2' ] . ', ' . $m[ 's3p1' ] . '-' . $m[ 's3p2' ] . '</td>'; } elseif ( $m[ 'p2' ] == $c ) { $output .= '<td>' . $m[ 'p1' ] . '<br>' . $m[ 's1p2' ] . '-' . $m[ 's1p1' ] . ', ' . $m[ 's2p2' ] . '-' . $m[ 's2p1' ] . ', ' . $m[ 's3p2' ] . '-' . $m[ 's3p1' ] . '</td>'; } } $output .= '</tr></tbody></table>'; } Please let me know your thoughts?
  21. Ok, let's try one more time. I changed my array script to this: $match[] = array( 'p1' => $related_user_1[ 0 ][ 'ID' ], 'p2' => $related_user_2[ 0 ][ 'ID' ], 's1p1' => $set_1_player_1, 's1p2' => $set_1_player_2, 's2p1' => $set_2_player_1, 's2p2' => $set_2_player_2, 's3p1' => $set_3_player_1, 's3p2' => $set_3_player_2, ); This will give me the following var_export: array ( 0 => array ( 'p1' => 'Sam Bina', 'p2' => 'David Smith', 's1p1' => array ( ), 's1p2' => array ( ), 's2p1' => array ( ), 's2p2' => array ( ), 's3p1' => array ( ), 's3p2' => array ( ), ), 1 => array ( 'p1' => 'Sam Bina', 'p2' => 'Fred Thompson', 's1p1' => array ( ), 's1p2' => array ( ), 's2p1' => array ( ), 's2p2' => array ( ), 's3p1' => array ( ), 's3p2' => array ( ), ), 2 => array ( 'p1' => 'Fred Thompson', 'p2' => 'Frank Molino', 's1p1' => array ( ), 's1p2' => array ( ), 's2p1' => array ( ), 's2p2' => array ( ), 's3p1' => array ( ), 's3p2' => array ( ), ), 3 => array ( 'p1' => 'Frank Molino', 'p2' => 'David Smith', 's1p1' => array ( ), 's1p2' => array ( ), 's2p1' => array ( ), 's2p2' => array ( ), 's3p1' => array ( ), 's3p2' => array ( ), ), 4 => array ( 'p1' => 'Sam Bina', 'p2' => 'Fred Thompson', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '2', ), 's2p1' => array ( 0 => '3', ), 's2p2' => array ( 0 => '6', ), 's3p1' => array ( ), 's3p2' => array ( ), ), 5 => array ( 'p1' => 'Frank Molino', 'p2' => 'David Smith', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '1', ), 's2p1' => array ( 0 => '6', ), 's2p2' => array ( 0 => '2', ), 's3p1' => array ( ), 's3p2' => array ( ), ), 6 => array ( 'p1' => 'Fred Thompson', 'p2' => 'Frank Molino', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '2', ), 's2p1' => array ( 0 => '7', ), 's2p2' => array ( 0 => '5', ), 's3p1' => array ( ), 's3p2' => array ( ), ), 7 => array ( 'p1' => 'Fred Thompson', 'p2' => 'David Smith', 's1p1' => array ( 0 => '5', ), 's1p2' => array ( 0 => '7', ), 's2p1' => array ( 0 => '7', ), 's2p2' => array ( 0 => '5', ), 's3p1' => array ( 0 => '6', ), 's3p2' => array ( 0 => '3', ), ), 8 => array ( 'p1' => 'Fred Thompson', 'p2' => 'David Smith', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '2', ), 's2p1' => array ( 0 => '6', ), 's2p2' => array ( 0 => '1', ), 's3p1' => array ( ), 's3p2' => array ( ), ), 9 => array ( 'p1' => 'Sam Bina', 'p2' => 'Frank Molino', 's1p1' => array ( 0 => '1', ), 's1p2' => array ( 0 => '6', ), 's2p1' => array ( 0 => '2', ), 's2p2' => array ( 0 => '6', ), 's3p1' => array ( ), 's3p2' => array ( ), ), 10 => array ( 'p1' => 'Sam Bina', 'p2' => 'David Smith', 's1p1' => array ( 0 => '3', ), 's1p2' => array ( 0 => '6', ), 's2p1' => array ( 0 => '6', ), 's2p2' => array ( 0 => '3', ), 's3p1' => array ( 0 => '6', ), 's3p2' => array ( 0 => '2', ), ), 11 => array ( 'p1' => 'Sam Bina', 'p2' => 'Frank Molino', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '4', ), 's2p1' => array ( 0 => '6', ), 's2p2' => array ( 0 => '4', ), 's3p1' => array ( ), 's3p2' => array ( ), ), ) Can this be used to create the table?
  22. I created some dummy users, matches and results to make it easier to read the output. Here is the var_export for $pair_id. Please let me know if you need other information: array ( 0 => array ( 'Sam Bina' => array ( 'u2' => 'David Smith', 's1p1' => array ( ), 's1p2' => array ( ), 's2p1' => array ( ), 's2p2' => array ( ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), 1 => array ( 'Sam Bina' => array ( 'u2' => 'Fred Thompson', 's1p1' => array ( ), 's1p2' => array ( ), 's2p1' => array ( ), 's2p2' => array ( ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), 2 => array ( 'Fred Thompson' => array ( 'u2' => 'Frank Molino', 's1p1' => array ( ), 's1p2' => array ( ), 's2p1' => array ( ), 's2p2' => array ( ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), 3 => array ( 'Frank Molino' => array ( 'u2' => 'David Smith', 's1p1' => array ( ), 's1p2' => array ( ), 's2p1' => array ( ), 's2p2' => array ( ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), 4 => array ( 'Sam Bina' => array ( 'u2' => 'Fred Thompson', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '2', ), 's2p1' => array ( 0 => '3', ), 's2p2' => array ( 0 => '6', ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), 5 => array ( 'Frank Molino' => array ( 'u2' => 'David Smith', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '1', ), 's2p1' => array ( 0 => '6', ), 's2p2' => array ( 0 => '2', ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), 6 => array ( 'Fred Thompson' => array ( 'u2' => 'Frank Molino', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '2', ), 's2p1' => array ( 0 => '7', ), 's2p2' => array ( 0 => '5', ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), 7 => array ( 'Fred Thompson' => array ( 'u2' => 'David Smith', 's1p1' => array ( 0 => '5', ), 's1p2' => array ( 0 => '7', ), 's2p1' => array ( 0 => '7', ), 's2p2' => array ( 0 => '5', ), 's3p1' => array ( 0 => '6', ), 's3p2' => array ( 0 => '3', ), ), ), 8 => array ( 'Fred Thompson' => array ( 'u2' => 'David Smith', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '2', ), 's2p1' => array ( 0 => '6', ), 's2p2' => array ( 0 => '1', ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), 9 => array ( 'Sam Bina' => array ( 'u2' => 'Frank Molino', 's1p1' => array ( 0 => '1', ), 's1p2' => array ( 0 => '6', ), 's2p1' => array ( 0 => '2', ), 's2p2' => array ( 0 => '6', ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), 10 => array ( 'Sam Bina' => array ( 'u2' => 'David Smith', 's1p1' => array ( 0 => '3', ), 's1p2' => array ( 0 => '6', ), 's2p1' => array ( 0 => '6', ), 's2p2' => array ( 0 => '3', ), 's3p1' => array ( 0 => '6', ), 's3p2' => array ( 0 => '2', ), ), ), 11 => array ( 'Sam Bina' => array ( 'u2' => 'Frank Molino', 's1p1' => array ( 0 => '6', ), 's1p2' => array ( 0 => '4', ), 's2p1' => array ( 0 => '6', ), 's2p2' => array ( 0 => '4', ), 's3p1' => array ( ), 's3p2' => array ( ), ), ), )
  23. You won't make it worse. Let me explain, The line get_post_meta( $match_id, 'related_user_1' ) captures the user array for player 1. ( we need to add [ 0 ][ 'ID' ] to get the ID) change 'related_user_1' and you will get other results from the match: related_user_2 will be player 2 set_1_player_1 is the value for first set, player 1. This is not an array. It is just the value itself. set_1_player_2 is the value for first set, player 2. This is not an array. It is just the value itself. and so on. All the above are running in a while() loop so that it captures all the results for the event. Each time this loop runs, it collects the data for one match, which should go into one cell in my table (except for the player 1 that goes to the first column). This part below ($pair_id .....) , is my attempt to create an array. This is where I need the help to setup appropriate array so that I can create my table. $pair_id[] = array( $related_user_1[ 0 ][ 'ID' ] => array( 'u2' => $related_user_2[ 0 ][ 'ID' ], 's1p1' => $set_1_player_1, 's1p2' => $set_1_player_2, 's2p1' => $set_2_player_1, 's2p2' => $set_2_player_2, 's3p1' => $set_3_player_1, 's3p2' => $set_3_player_2, ), );
  24. That's my problem with the code. I don't know how to fix or make the array so that I can use the data to generate the table. It does't have to be if you know a way to get the the table. Please feel free to change my code that I posted above to whatever you think it will work.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.