0

I created custom post type and custom taxonomy. But I use ACF, and is need to get ID of current page Post type is 'objects'. Custom taxonomy is "objects_category". And page name taxonomy-objects_category.php

This code no works

$two_cols_catalog_left  = get_field('two_cols_catalog_left');
echo $two_cols_catalog_left;

But this code works

$two_cols_catalog_left  = get_field('two_cols_catalog_left', 47);
echo $two_cols_catalog_left;

47 - is ID of current page.

But is need to type

 $two_cols_catalog_left  = get_field('two_cols_catalog_left', $page_id);
 echo $two_cols_catalog_left;

How is possible to get ID of current page?

2
  • In order to get use get_field without a post ID parameter you need to be within the "loop". So ensure you've initiated the loop when you're using it and you wont need to manually get the ID.
    – Paul G.
    Feb 2, 2021 at 9:37
  • Check out get_queried_object_id Feb 2, 2021 at 10:03

1 Answer 1

0
$term = get_term_by( 'name', 'Дома 5, 'category' );
echo $term->term_id;
1
  • If you're already on the taxonomy archive page though there must be a better way to do this than looking up the term from the database.
    – Rup
    Feb 3, 2021 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.