It seems like you’re trying to use $wpdb without first declaring the global $wpdb. You should not need to enqueue admin.php in order to use $wpdb.
add:
global $wpdb;
to the top of your function instead.
If you’re trying to run code in a file without passing it via wordpress (i.e. you’re just navigating to /somefile.php) make sure you include wp-load.php (although this is NOT best practice).
Related Posts:
- Customize profile.php
- How can i change email template for new user
- Enable page templates. How?
- Is it possible to override the result of get_template_part()?
- Prevent comments_template() to load comments.php
- Page editor missing Templates drop down
- How to find the posts page (home page) programatically
- Custom templates folder
- How to Rename a Template File?
- get page templates
- How to assign a class to a page with a custom template?
- Proper Javascript Implementation
- Guest author’s post not display in author template
- How to apply a custom template for posts by default?
- Unable to set right time in admin and frontend template
- Get templated page/post content via the WordPress API
- Force all images to full size in page template
- Is there a way to check which template file is being loaded, if it is not a page template file?
- When a link doesn’t exist, how to tell WordPress what to do? (404 Error Page)
- How to remove wp_link_pages() from template
- How can I get WP to use templates in lower-level subfolder?
- how to make a home page for wordpress custom theme
- Generate Catalog Of Posts Based On Template
- Extending body classes in front- and backend
- How do I find the directory of a page template?
- get_post_metadata() undefined when used in loop in RSS template
- the_excerpt producing empty output
- Getting term description in single post template
- New custom nev not working [closed]
- Cannot edit style.css from admin panel, because the template is looking for style.min.css
- How do I insert JS tracking code to a page with the WP editor?
- LaTeX for WordPress strips codes in loop
- How to remove the Template drop down, but keep Parent and Order
- Search results when none found – stay on page they were on
- Include Lumen/Laravel app in custom WordPress template
- Rewrite Rules to custom template
- Unable to display pagination links on custom category template
- How to change header image size in custom themes
- Different Template based on HTTP Referer
- Where is Number of Posts Set?
- How can I force URL of a custom post type archive to use a page template?
- Possible to have one template call different sidebars for different pages?
- How does WordPress choose archive type template?
- How to properly Remove certain CSS / JS files from template
- What is the most efficient way to create multiple versions of the same template?
- Are there any downsides to not using get_header(), get_sidebar and get_footer()?
- How do I get the page template name chosen?
- How can I add text to a specific ‘Edit Page’?
- Automatically use specific template to load subpages
- If Posted After Date
- No three-columns template in TwentyEleven?
- Update template without undoing all my edits?
- How to get and set the post tag value within WP Query from URL?
- Can’t split the_title() by white space
- Not so common HTML transition to wordpress issue
- Differentiation between index.php and page.php
- Undefined get_header function
- Single-page.php template file name not shown
- WordPress custom template not showing in the list of available templates
- How to create new template page and template-parts in wordpress theme [closed]
- how to properly include or get file contents in a wordpress theme
- How to display custom post type?
- Pagination issue with tag.php
- How are the HTML classes generated?
- Page Template with Sidebar Naming Convention?
- Adding text to the footer of each post based on tags or categories
- Including template pages within another template?
- Blog page won’t show Blog template
- How can I abstract code out of a template by using functions.php
- Make Permalink go to specific template
- WordPress function.php on ZendFramework CMS
- Site Title appearing twice on live site
- Give user option to select full post index page or excerpted index?
- how to change already posted blog to custom template wordpress?
- Editing my loop-page.php causes posts to show on all pages
- WordPress change title with custom dynamic
- template with multiple post loops for multiple widgets [duplicate]
- Random home page at each refresh between array of page IDs
- Do not trigger page 404 on custom template
- Print different parts of content in template
- How can I pass a variable from a template to header.php of a theme
- How can i conditionally load taxonomy-{taxonomy}.php template php files through functions.php
- Page Template Selector Error
- WordPress site not loading styles on desktop?
- Display all page which have not a certain template
- Change Page Template Based on URL Rewrite in WordPress
- ACF – Attach JS file depending on ACF field
- I want to display all related posts for a selected tag in WordPress
- WordPress Child Theme Template auth_redirect wrapper
- why get_header doesn’t work twice in a test
- Show a custom template, no matter the page being viewed, if the user is not logged in
- printf, translation and the_author_posts_link()
- Tag Posts showing in wrong places
- How can I setup custom templates for a meta-data query
- front page won’t change templates
- Including 2 Negative Is_Template Conditionals in header.php [closed]
- Add custom card template to masonry layout using Essential Grid [closed]
- Where is the general html template file?
- templates page not showing on gutenberg editor
- How to load php templates from html page (block theme)