Custom Database Queries in WordPress | WordPress Tutorials

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ต.ค. 2024
  • Custom WordPress Database Queries as requested.. Use $wpdb WordPress object to do a database query.
    Company Website: www.ideapro.com
    SEND BUSINESS CORRESPONDENCE TO:
    Idea Pro LLC or Joshua Herbison
    2901 E Greenway Rd. #54171
    Phoenix, AZ 85032
    In my tutorials, you will see me upload files to the server. To upload, I use Sublime Text 3 with SFTP by WBond. idp.bz/sftp
    WordPress Codex: idp.bz/wordpres...

ความคิดเห็น • 105

  • @razakhan3472
    @razakhan3472 3 ปีที่แล้ว +7

    Hi, Joshua Herbison I would like to say that you are doing wonderful at educating people I have seen lots of tutorial videos but the way you clear things at a level that even a novice person can understand you (and I love that you don't just assume that the person who is watching have that knowledge already) . Thumbs up and you got a new subscriber. Keep it up and keep bringing these types of videos

    • @jherbison
      @jherbison  3 ปีที่แล้ว +1

      Awesome! Thank you for watching and commenting..

  • @turb0z
    @turb0z ปีที่แล้ว

    I'm doing some custom messaging for a customer in their wordpress environment and this saved me tons of time perusing through the developer documentation. Thank you so much for the thorough explanation. Thought you'd like to know that after 3 years, this video is still providing value!

  • @adeyemi4182
    @adeyemi4182 หลายเดือนก่อน

    That is awesome. It really assists beginners on WordPress to understand how effectively query data from the database. However, how would the user navigate to the result of the query page on the browser without manually entering the url? I love the method of teaching. Clear, concise and visual are visible.

  • @jherbison
    @jherbison  5 ปีที่แล้ว +3

    Queries can get extensive. If you understand creating custom queries, you can create great dynamic websites far beyond the possibilities of WordPress. Hope you all enjoy the video. Creators that are looking to collaborate with other creators should checkout collab.tube

  • @BarisPalabiyik
    @BarisPalabiyik 3 ปีที่แล้ว +1

    This was very very well made, and a total lifesaver for many people in various projects Joshua. Keep it up you are helping a lot.

    • @jherbison
      @jherbison  3 ปีที่แล้ว

      Thank you for watching and commenting.

  • @pavman42
    @pavman42 ปีที่แล้ว

    This was helpful. I was having issues in-lining php db calls and figured out about 13 minutes into your video that I had a couple of missing semi-colons scattered about. Was able to do what I needed to do w/o all Google misdirection out there. Even found a nice shortcode plugin for php as all the php inline html attempts at presenting table data seemed to fail miserably. While it's still a bit kludgy, and wordpress is still mostly inelegant, at least I can create a data-centric site now. Still beats writing node and a front-end from scratch. Protip: create stored procedures to cut down on the database load with $wpdb calls.

  • @AlexHaff
    @AlexHaff 2 ปีที่แล้ว +1

    This is immensely helpful - has been more effective for me than some courses. Thank you!

    • @jherbison
      @jherbison  2 ปีที่แล้ว

      Thank you for watching and commenting.

  • @t.w.freiburg6125
    @t.w.freiburg6125 4 ปีที่แล้ว +3

    Great! You are a wonderful teacher. Very helpful. Thanks

    • @jherbison
      @jherbison  4 ปีที่แล้ว

      Thank you for the compliment and comment.

  • @then8137
    @then8137 3 ปีที่แล้ว +1

    DUD ty
    rrrrrrrrrllllllllly ty
    you're lookin directly and answer full of the problem
    more people dont do this ...
    ty

    • @jherbison
      @jherbison  3 ปีที่แล้ว

      Awesome.. Thank you for watching and commenting.

  • @theman7050
    @theman7050 3 ปีที่แล้ว +1

    Great vid again! Would love a custom tables creation and CRUD tutorial in future. :)

    • @jherbison
      @jherbison  3 ปีที่แล้ว +1

      Awesome. Thanks for watching and commenting.

  • @philip9677
    @philip9677 3 ปีที่แล้ว +1

    I didn’t know you could do sql type queries directly in Wordpress awesome

    • @jherbison
      @jherbison  3 ปีที่แล้ว +1

      Thank you for the comment and watching.

  • @DManFromMars
    @DManFromMars 4 ปีที่แล้ว +1

    Well done. I looked around for this information so much, and this was straight forward and clearly explained.

    • @jherbison
      @jherbison  4 ปีที่แล้ว +1

      Thank you for the comment. Glad you liked it.

  • @jlcdrivewayramps7343
    @jlcdrivewayramps7343 3 ปีที่แล้ว +1

    Super clear and easy to understand.!!!!. Thank you.

    • @jherbison
      @jherbison  3 ปีที่แล้ว

      Thank you for watching and commenting.. Glad to hear it was clear and easy to understand.

  • @treycranson
    @treycranson 3 ปีที่แล้ว +2

    Sounds like loads of people want to custom query the WP database, but what if we want to query a second database that is holding a dataset unrelated to Wordpress?

    • @jherbison
      @jherbison  3 ปีที่แล้ว +1

      Thank you for the question. It can be done, but you would need to connect to the second database and make sure to not conflict with your current DB connection. I would suggest creating an API style code outside of your WordPress install to the second database and then use something like cURL to pull in that data that you fetch from the cURL command. If you have more details or an example, I could make a video explaining it.

  • @TW-ik3br
    @TW-ik3br 4 ปีที่แล้ว +2

    You are awesome. SUBSCRIBED! Keep it rolling. I'm having some issues connecting my gravity form to my own database [not WordPress tables] can you do a video about that? Thank you.

    • @jherbison
      @jherbison  4 ปีที่แล้ว

      So is the website WordPress, and then you have a different database that holds the gravity form information?

    • @dudefromhome
      @dudefromhome 4 ปีที่แล้ว

      @@jherbison YES. That's is exactly my situation. What options do I have to implement that?
      FYI: It's also a MySQL database.

  • @ottavinognata5355
    @ottavinognata5355 4 ปีที่แล้ว +1

    Thank you Joshua , these videos are very well made and very usefull. Many thanks.

    • @jherbison
      @jherbison  4 ปีที่แล้ว

      Glad you like them. Thank you for watching and commenting.

  • @SkyrimBeast
    @SkyrimBeast 3 ปีที่แล้ว +2

    Be wary of using require_once( "wp-load.php" ); Some hosting environments have the root directory WP files symlinked. What this means is the typical WP root directory files won't be where we might think they are. Using require_once() in this fashion, as we saw, will trigger a fatal error every time. Great video though Joshua, many thanks :-)

    • @jherbison
      @jherbison  3 ปีที่แล้ว +6

      When commenting something like that, please explain what they should do instead! Thank you.

  • @crazycreativecat
    @crazycreativecat 7 หลายเดือนก่อน +1

    Great tutorial!

    • @jherbison
      @jherbison  7 หลายเดือนก่อน

      Thank you! Thank you for watching and commenting.

  • @jhjh111
    @jhjh111 3 ปีที่แล้ว +1

    Great Video. But I want to hear more about a main wp site and a subdomain wp site sharing data. in other words, I have a wp site installed on a subdomain that I want to query data from the "parent" wp site. Both are using the same data server but individual dbs. you briefly mentioned something about this. any chance you're working on a plugin?

    • @jherbison
      @jherbison  2 ปีที่แล้ว

      Thank you. Hope you found a solution for this as I missed your comment. There are many ways to do this. Thank you for watching and commenting.

  • @user-vk9or7nn9r
    @user-vk9or7nn9r 3 ปีที่แล้ว +1

    Thanks, would be nice to put the data into the admin users panel column, and instead of the post data let's say, take whatever data from database and fill each users row, like ID, but as you explain we will understand how, hehe. I made it myself but couldn't get users data made by other plugin in it's own table. For users ID column there's plenty of tuts.

    • @jherbison
      @jherbison  2 ปีที่แล้ว

      Thank you for watching and commenting. I am trying to catch up on comments that I missed.

  • @sofakritic6914
    @sofakritic6914 4 ปีที่แล้ว +1

    Thats tutorial helped me with my actual website. I use ACF plugin and I Needed to pull out countries from data base. So hard coded countries is possible to pull out, now I need to think how to by switching the countries. Thanks anyway!

    • @jherbison
      @jherbison  4 ปีที่แล้ว

      Not exactly sure what you meant, but hope the video helped and thank you for commenting.

  • @vaibhavp
    @vaibhavp 3 ปีที่แล้ว +1

    Hey Joshua, great explanation. I’ve a doubt, I’m using a plug-in to manage custom listings(posts) on my Wordpress website. Now I want to sort these listings by distance. I managed to write a sql query for the same, using which I’m able to fetch the posts ID ordered by distance. Now when I try to fetch posts data using wp query for the corresponding IDs I’m getting them in random order. How can I preserve the order of posts fetched from custom query?

    • @vaibhavp
      @vaibhavp 3 ปีที่แล้ว +1

      Also I’m using get_col() because apparently get_results() was causing critical errors. [undefined function get_results]

    • @jherbison
      @jherbison  3 ปีที่แล้ว +1

      It shouldn’t give you an error of undefined function unless you are calling that function before Wordpress core has loaded the function. It would be interesting to see how your code is setup.

    • @jherbison
      @jherbison  3 ปีที่แล้ว +1

      As far as the query, are you trying to sort by the distance from a given point? Where is the distance stored? As meta value?

    • @vaibhavp
      @vaibhavp 3 ปีที่แล้ว +1

      @@jherbison I can hop on a zoom meeting(screen share) or something if you are available.

    • @vaibhavp
      @vaibhavp 3 ปีที่แล้ว

      @@jherbison Yes, starting from a given point. I made a view in the database for the same since the data was scattered all over. And using the sql query in view to sort.

  • @ivanlik
    @ivanlik 3 ปีที่แล้ว +1

    Great! , how we can speed up search in post content ? , that is not indexed ?

    • @jherbison
      @jherbison  3 ปีที่แล้ว +1

      Yes, searching the post_content is slow. I would suggest adding tags to the post for the keywords that are searched most or what words you think are searched for. Not really anyway to speed it up unless you find keywords in the post_content and put those automatically as tags.

  • @abdulrehman5505
    @abdulrehman5505 3 ปีที่แล้ว +1

    Good Work, Comment from Pakistan.

    • @jherbison
      @jherbison  3 ปีที่แล้ว

      Thank you! Welcome!

  • @jjsaladins
    @jjsaladins 4 ปีที่แล้ว +1

    Thanks for the great content!
    I've gotten here because I'm running an affiliate program within my website and I'm needing to display specific content within the landing page for each Referror.
    The use case would be something like this (Jhon enrols to the referral program; Jhon includes a link instead of his home address within the address field; WP Affiliate Manager register Jhon and generates his unique link; Jhon shates his link to Jenna; Jenna cliks on Jhons link; Jenna gets to the LandingPage and sees Jhon's link on a section of the page).
    Thanks to you I now have and idea on how to resolve the puzzle... If you could help me some more... I'd bee a grateful follower of yours for ever!

    • @jherbison
      @jherbison  4 ปีที่แล้ว

      Glad you understand a little more about your solution. Not sure what you need help with. If you need to you can add a function and modify the content with add_filter('the_content','YOUR_FUNCTION_NAME');
      Let me know if that makes sense.

  • @gauravp4468
    @gauravp4468 4 ปีที่แล้ว +1

    Cool, can we make section in page or theme customize panel to show content by post type and category like elemntor advance query control

    • @jherbison
      @jherbison  2 ปีที่แล้ว

      I hope you found a solution for this.. If not, can you explain a little more about it?
      Trying to catch up on comments that I missed.
      Thank you for watching and commenting.
      If you haven't already, please check out my latest video: A Day In the life of a software engineer. th-cam.com/video/Z8GluDQ2U-E/w-d-xo.html

  • @timsteeman8847
    @timsteeman8847 2 ปีที่แล้ว +1

    Hi Joshua, which php-editor are using?

    • @jherbison
      @jherbison  2 ปีที่แล้ว

      Sublime text

    • @jherbison
      @jherbison  2 ปีที่แล้ว

      Thank you for watching and commenting.

    • @timsteeman8847
      @timsteeman8847 2 ปีที่แล้ว

      @@jherbison Thank you

  • @ShannonWhitty
    @ShannonWhitty 4 ปีที่แล้ว +1

    Do you have any guides that show how you call this through an Ajax call? I am building an Admin page using DataTables with the data being loaded via an Ajax call. But the Ajax page has no WP loaded

    • @jherbison
      @jherbison  4 ปีที่แล้ว +1

      On the ajax page that is loaded, use require_once('PATH_TO_ROOT_WORDPRESS_FOLDER/wp-load.php');
      Then WordPress is loaded on that page.

    • @ShannonWhitty
      @ShannonWhitty 4 ปีที่แล้ว

      ​@@jherbison Thanks for replying. I went onto to some other tutorials and learnt about admin-ajax.php and nonce and have built my very first plugin. Will have to show you sometime

  • @Nazreen
    @Nazreen 4 ปีที่แล้ว +1

    Great explanation. Well, put together. 👍

    • @jherbison
      @jherbison  4 ปีที่แล้ว

      Thank you for watching and commenting.

  • @wastedart1794
    @wastedart1794 2 ปีที่แล้ว

    Hello Joshua, i have a issue with my get_the__date() gives me the wrong current date, do you know how i can fix this issue, or do you hve any videos covering this? :)

  • @salmanrazakmemon
    @salmanrazakmemon 4 ปีที่แล้ว +1

    hi,
    how to show woocommerce product inventory (counter). i am integrating POS with online store. Based on my POS quantity I want to change website inventory stock.

    • @jherbison
      @jherbison  4 ปีที่แล้ว

      I have not dug into woocommerce that much as I don't like it. I have only been in to fix errors. If I get time, I will take a look at it and see how to update the quantity. Thank you for watching and commenting.

  • @MobiusCoin
    @MobiusCoin 4 ปีที่แล้ว +1

    I've always been curious about this but I'm trying to think of situations where I would have to resort to this instead of WP_Query.

    • @jherbison
      @jherbison  4 ปีที่แล้ว

      That's cool.. You can use WP_Query.

  • @mastahhdigital4178
    @mastahhdigital4178 4 ปีที่แล้ว +2

    Please make the complete course for wordpress

    • @jherbison
      @jherbison  4 ปีที่แล้ว +1

      Thank you for the comment.

  • @DDDD-ns9re
    @DDDD-ns9re 4 ปีที่แล้ว +1

    Keep posting Joshua !!

    • @jherbison
      @jherbison  4 ปีที่แล้ว

      Thank you. I have some videos in the queue, just haven't had time to get them recorded. Thank you for the comment.

  • @bonniesitessolutions7728
    @bonniesitessolutions7728 3 ปีที่แล้ว +1

    There has been a recent update to Wordpress core, about a week ago. Is this still safe to use and won't break anything?

    • @jherbison
      @jherbison  3 ปีที่แล้ว +1

      Yes, it still works and should not break anything unless you write the query wrong.. I would always do it in a dev staging area before doing it on a live website. Thank you for watching and commenting.

    • @bonniesitessolutions7728
      @bonniesitessolutions7728 3 ปีที่แล้ว +1

      @@jherbison Thanks for the quick reply!

    • @bonniesitessolutions7728
      @bonniesitessolutions7728 3 ปีที่แล้ว +1

      @@jherbison ps: your tubebuddy link is broken

    • @jherbison
      @jherbison  3 ปีที่แล้ว

      Yeah, I need to remove it. I stopped using TubeBuddy as it was too expensive for what I was getting out of it. Thank you for letting me know. Forgot it was even still a link on the description.

    • @jherbison
      @jherbison  3 ปีที่แล้ว

      Your welcome. Sometimes I have more time to reply then other times.

  • @passionartw
    @passionartw 4 ปีที่แล้ว +1

    is this method works with products also?

    • @jherbison
      @jherbison  4 ปีที่แล้ว

      Yes, you should be able to query any information in the database. Thank you for the comment.

  • @dkimeiyd
    @dkimeiyd 3 ปีที่แล้ว +1

    Thank you so much!

    • @jherbison
      @jherbison  3 ปีที่แล้ว

      You're welcome.. Thank you for watching and commenting.

  • @timr5078
    @timr5078 4 ปีที่แล้ว +1

    including wp-load.php does not work with Updated WP 5.4, on my local machine with php 5 something, but on previous vesions is ok

    • @jherbison
      @jherbison  4 ปีที่แล้ว

      You should be using php 7 at minimum. It should work on all versions of WordPress since about version 4.. Maybe the path is wrong. Hope you were able to figure it out. Thank you for watching and commenting.

  • @pawanmaurya7146
    @pawanmaurya7146 3 ปีที่แล้ว +1

    this tutorial was very helpful I need your help in the same kind of project. can you help me?

    • @jherbison
      @jherbison  3 ปีที่แล้ว

      Hope you were able to figure out your project.. Thank you for watching and commenting.

  • @raywebb8215
    @raywebb8215 4 ปีที่แล้ว +1

    I have a question.... where are you doing this from?

    • @jherbison
      @jherbison  4 ปีที่แล้ว

      Do you mean location? If so, my home office in Scottsdale Arizona.

    • @raywebb8215
      @raywebb8215 4 ปีที่แล้ว

      I was more interested in a directory path but I’ll type in your city and state and see what I get... 😉

  • @maguilecutty
    @maguilecutty 4 ปีที่แล้ว +3

    Dude if you dont already have one, you need to make a udemy course for selling your awesome knowledge!

    • @jherbison
      @jherbison  4 ปีที่แล้ว +7

      Thank you. It isn’t about the money. I enjoy helping others. If I did it as a course on udemy, then it would become a job! Thank you for the comment.

    • @chuksezeilo
      @chuksezeilo 4 ปีที่แล้ว +1

      @@jherbison interesting perspective! I actually jump out of the Udemy course to come here and get some clarification. Your pace is so much more natural. I guess your perspective on doing the videos is the reason why you do them so well.

  • @danielwatson6529
    @danielwatson6529 3 ปีที่แล้ว +1

    5:00 sound like hacking 🤣

    • @jherbison
      @jherbison  3 ปีที่แล้ว

      Not hacking at all.. Just writing the code to your benefit.. Hacking would be accessing someone else's admin area... ;-)

  • @edington6302
    @edington6302 3 ปีที่แล้ว +1

    My database failing to connect even after following step by step.

    • @jherbison
      @jherbison  3 ปีที่แล้ว

      Can you email me your code to josh@ideapro.com so I can see what is happening? Thank you for watching and commenting.

  • @kulvindersingh2738
    @kulvindersingh2738 5 ปีที่แล้ว +1

    Thank you sir !

    • @jherbison
      @jherbison  5 ปีที่แล้ว +1

      You’re welcome. Hope it helped. Please share the video with anyone that it can help. I really want to start growing the channel but need more subs and views. Thank you for your help and comment.

    • @kulvindersingh2738
      @kulvindersingh2738 5 ปีที่แล้ว

      @@jherbison sure sir!

  • @ValtrX
    @ValtrX 3 ปีที่แล้ว +1

    Thank you so much!

    • @jherbison
      @jherbison  2 ปีที่แล้ว +1

      Thank you for watching and commenting.. Trying to catch up on comments.